CSS Cheat Sheet

In CSS

Cascading Style Sheets (CSS) is a stylesheet language used to describe the presentation of a document written in HTML or XML. CSS provides a way to style HTML elements and create visually appealing web pages. CSS is widely used in web development and is a key tool for creating responsive and dynamic web pages.

This cheat sheet provides a quick reference for the most commonly used CSS properties organized into themes. Each theme contains a table with the property name and a brief description of its purpose. The cheat sheet covers a wide range of CSS properties, from basic text and background styles to advanced animation and transformation effects.

Using this cheat sheet can save you time and help you write cleaner, more efficient CSS code. By having all the CSS properties organized into themes, you can easily find the property you need and quickly add it to your code. This cheat sheet can also help you learn new CSS properties and how they can be used to create different styles and effects.

In conclusion, CSS is an essential tool for web development and this cheat sheet is a handy resource for anyone who works with CSS. By using this cheat sheet, you can improve your CSS skills and create more visually appealing and dynamic web pages.

Cheat Sheet

Basic Syntax

CSS SelectorDescription
*Selects all elements
elementSelects all elements of a specific type
.classSelects all elements with a specific class
#idSelects the element with a specific ID
selector1, selector2Selects all elements that match either selector1 or selector2
selector1 selector2Selects all elements that match selector2 and are descendants of elements that match selector1
selector1 > selector2Selects all elements that match selector2 and are direct children of elements that match selector1
selector1 + selector2Selects the element that immediately follows selector1 and matches selector2
selector1 ~ selector2Selects all elements that follow selector1 and match selector2

Text Properties

PropertyDescription
colorSets the color of text
font-sizeSets the size of text
font-weightSets the weight of text (e.g. bold)
font-styleSets the style of text (e.g. italic)
text-alignSets the alignment of text
text-decorationSets the decoration of text (e.g. underline)
text-transformSets the case of text (e.g. uppercase)
line-heightSets the height of a line of text
letter-spacingSets the spacing between letters
word-spacingSets the spacing between words
white-spaceSets how white space is handled
text-shadowAdds a shadow to text

Box Properties

PropertyDescription
widthSets the width of an element
heightSets the height of an element
marginSets the margin of an element
margin-topSets the top margin of an element
margin-rightSets the right margin of an element
margin-bottomSets the bottom margin of an element
margin-leftSets the left margin of an element
paddingSets the padding of an element
padding-topSets the top padding of an element
padding-rightSets the right padding of an element
padding-bottomSets the bottom padding of an element
padding-leftSets the left padding of an element
borderSets the border of an element
border-topSets the top border of an element
border-rightSets the right border of an element
border-bottomSets the bottom border of an element
border-leftSets the left border of an element
border-widthSets the width of a border
border-styleSets the style of a border
border-colorSets the color of a border
border-radiusSets the radius of a border
box-sizingSets the box model for an element
overflowSets how content that overflows an element is handled
displaySets the display style of an element
visibilitySets the visibility of an element

Background Properties

PropertyDescription
background-colorSets the color of an element’s background
background-imageSets an image as an element’s background
background-repeatSets how an element’s background image is repeated
background-positionSets the position of an element’s background image
background-sizeSets the size of an element’s background image
background-attachmentSets whether an element’s background image scrolls with the page or is fixed

Positioning Properties

Property ——Description
position Specifies the type of positioning used for an element
topSets the distance between the top edge of an element and the top edge of its containing element
bottom. Sets the distance between the bottom edge of an element and the bottom edge of its containing element
leftSets the distance between the left edge of an element and the left edge of its containing element
rightSets the distance between the right edge of an element and the right edge of its containing element
z-indexSets the stacking order of elements
floatSpecifies whether or not an element should float
clearSpecifies which sides of an element other floating elements are not allowed

Flexbox Properties

PropertyDescription
display: flexSets an element as a flex container
flex-directionSets the direction of the flex container
justify-contentSets the alignment of flex items along the main axis
align-itemsSets the alignment of flex items along the cross axis
flex-wrapSets whether flex items should wrap
align-contentSets the alignment of flex lines along the cross axis
flexSets the flexible size of a flex item
orderSets the order of a flex item
align-selfSets the alignment of a single flex item along the cross axis

Grid Properties

PropertyDescription
display: gridSets an element as a grid container
grid-template-columnsSets the width of each column in the grid
grid-template-rowsSets the height of each row in the grid
grid-template-areasSets the position of grid items using named grid areas
grid-column-gapSets the gap between columns in the grid
grid-row-gapSets the gap between rows in the grid
grid-gapSets the gap between rows and columns in the grid
grid-auto-columnsSets the width of columns that aren’t explicitly sized in the grid
grid-auto-rowsSets the height of rows that aren’t explicitly sized in the grid
grid-auto-flowSets the flow of grid items that aren’t explicitly placed in the grid
grid-row-startSets the starting row position of a grid item
grid-row-endSets the ending row position of a grid item
grid-column-startSets the starting column position of a grid item
grid-column-endSets the ending column position of a grid item
grid-areaSets the grid item’s position using the grid-row-start, grid-row-end, grid-column-start, and grid-column-end properties

Animation and Transition Properties

PropertyDescription
animation-nameSets the name of an animation
animation-durationSets the length of an animation
animation-timing-functionSets the timing of an animation
animation-delaySets the delay before an animation starts
animation-iteration-countSets the number of times an animation should repeat
animation-directionSets the direction of an animation
animation-fill-modeSets what styles are applied to an element before and after an animation
animation-play-stateSets whether an animation is running or paused
transition-propertySets the CSS property to which a transition should be applied
transition-durationSets the length of a transition
transition-timing-functionSets the timing of a transition
transition-delaySets the delay before a transition starts

Responsive Design Properties

PropertyDescription
@mediaSets styles for different screen sizes
max-widthSets the maximum width of an element
min-widthSets the minimum width of an element
widthSets the width of an element
heightSets the height of an element
max-heightSets the maximum height of an element
min-heightSets the minimum height of an element
viewport unitsSets sizes relative to the viewport

Pseudo-class and Pseudo-element Properties

PropertyDescription
:activeSets the styles for an element when it is being activated
:hoverSets the styles for an element when it is being hovered
:focusSets the styles for an element when it has focus
:visitedSets the styles for a visited link
:beforeInserts content before the content of an element
:afterInserts content after the content of an element

Transform Properties

PropertyDescription
transformApplies a 2D or 3D transformation to an element
transform-originSets the origin point of a transformation
rotateRotates an element around a fixed point
scaleIncreases or decreases the size of an element
translateMoves an element along the horizontal and/or vertical axis
skewSkews an element along the horizontal and/or vertical axis

Reference:

https://developer.mozilla.org/en-US/docs/Web/CSS