Advanced CSS Cheat Sheet

<CSS_Cheat_Sheet/>

CSS Quick Reference

Welcome to the CSS Cheat Sheet! This guide provides a quick reference for commonly used CSS properties, selectors, and concepts. Whether you're a beginner learning CSS or an experienced developer looking for a quick refresher, this cheat sheet will help you find the right styles for your web projects. Explore the categories below to find the CSS properties and techniques you need.

Selectors

  • Universal Selector

    The universal selector (*) selects all elements on a page.

    
    * {
      margin: 0;
      padding: 0;
    }
                
  • Type Selector

    The type selector selects all elements of a given type.

    
    p {
      color: blue;
    }
                
  • Class Selector

    The class selector selects all elements with a specified class.

    
    .example {
      font-size: 20px;
    }
                
  • ID Selector

    The ID selector selects a single element with a specified ID.

    
    #unique {
      background-color: yellow;
    }
                
  • Attribute Selector

    The attribute selector selects elements based on an attribute or attribute value.

    
    a[href="https://example.com"] {
      color: red;
    }
                
  • Pseudo-class Selector

    The pseudo-class selector selects elements based on their state.

    
    a:hover {
      color: green;
    }
                
  • Pseudo-element Selector

    The pseudo-element selector selects a part of an element.

    
    p::first-line {
      font-weight: bold;
    }
                
  • Child Selector

    The child selector selects direct child elements of a specified element.

    
    ul > li {
      list-style-type: none;
    }
                
  • Descendant Selector

    The descendant selector selects all elements that are descendants of a specified element.

    
    div p {
      color: purple;
    }
                
  • Adjacent Sibling Selector

    The adjacent sibling selector selects an element that is immediately preceded by a specified element.

    
    h1 + p {
      margin-top: 0;
    }
                
  • General Sibling Selector

    The general sibling selector selects all elements that are siblings of a specified element.

    
    h1 ~ p {
      color: brown;
    }
                

Box Model

  • Content

    The actual content area of the box, where text and images appear.

    
    .example {
      width: 200px;
      height: 100px;
    }
                
  • Padding

    The space between the content and the border.

    
    .example {
      padding: 20px;
    }
                
  • Border

    The border that goes around the padding and content.

    
    .example {
      border: 1px solid #ccc;
    }
                
  • Margin

    The space outside the border.

    
    .example {
      margin: 10px;
    }
                
  • Width

    The width of the content area, excluding padding, border, and margin.

    
    .example {
      width: 300px;
    }
                
  • Height

    The height of the content area, excluding padding, border, and margin.

    
    .example {
      height: 150px;
    }
                
  • Box-Sizing

    Determines how the browser calculates the total width and height of an element.

    
    .example {
      box-sizing: border-box;
    }
                

Display and Visibility

  • display

    Specifies how an element is displayed.

    
    .example {
      display: block;
    }
                
  • visibility

    Specifies whether an element is visible or hidden.

    
    .example {
      visibility: hidden;
    }
                
  • opacity

    Specifies the transparency level of an element.

    
    .example {
      opacity: 0.5;
    }
                
  • overflow

    Specifies what happens if content overflows an element's box.

    
    .example {
      overflow: hidden;
    }
                
  • overflow-x

    Specifies what happens with the left/right edges of the content if it overflows the element's content area.

    
    .example {
      overflow-x: scroll;
    }
                
  • overflow-y

    Specifies what happens with the top/bottom edges of the content if it overflows the element's content area.

    
    .example {
      overflow-y: auto;
    }
                
  • clip

    Clips an absolutely positioned element.

    
    .example {
      clip: rect(0, 100px, 100px, 0);
    }
                
  • clip-path

    Defines the visible area of an element.

    
    .example {
      clip-path: circle(50% at 50% 50%);
    }
                
  • position

    Specifies the positioning method used for an element.

    
    .example {
      position: relative;
    }
                
  • top, right, bottom, left

    Specifies the position of a positioned element.

    
    .example {
      position: absolute;
      top: 0;
      left: 0;
    }
                
  • z-index

    Specifies the stack order of positioned elements.

    
    .example {
      z-index: 10;
    }
                

Positioning

  • position

    Specifies the positioning method used for an element.

    
    .example {
      position: relative;
    }
                
  • top, right, bottom, left

    Specifies the position of a positioned element.

    
    .example {
      position: absolute;
      top: 0;
      left: 0;
    }
                
  • z-index

    Specifies the stack order of positioned elements.

    
    .example {
      z-index: 10;
    }
                
  • float

    Specifies whether an element should float to the left, right, or none.

    
    .example {
      float: left;
    }
                
  • clear

    Specifies what elements can float beside the cleared element and on which sides.

    
    .example {
      clear: both;
    }
                
  • clip

    Clips an absolutely positioned element.

    
    .example {
      clip: rect(0, 100px, 100px, 0);
    }
                
  • clip-path

    Defines the visible area of an element.

    
    .example {
      clip-path: circle(50% at 50% 50%);
    }
                
  • overflow

    Specifies what happens if content overflows an element's box.

    
    .example {
      overflow: hidden;
    }
                
  • overflow-x

    Specifies what happens with the left/right edges of the content if it overflows the element's content area.

    
    .example {
      overflow-x: scroll;
    }
                
  • overflow-y

    Specifies what happens with the top/bottom edges of the content if it overflows the element's content area.

    
    .example {
      overflow-y: auto;
    }
                

Flexbox Properties I

  • display: flex;

    Defines a flex container.

    
    .container {
      display: flex;
    }
                
  • display: inline-flex;

    Defines an inline flex container.

    
    .container {
      display: inline-flex;
    }
                
  • flex-direction: row;

    Defines the direction of the flex container's main axis.

    
    .container {
      flex-direction: row;
    }
                
  • flex-direction: row-reverse;

    Reverses the main axis of the flex container.

    
    .container {
      flex-direction: row-reverse;
    }
                
  • flex-direction: column;

    Defines the main axis as vertical.

    
    .container {
      flex-direction: column;
    }
                
  • flex-direction: column-reverse;

    Reverses the main axis to vertical.

    
    .container {
      flex-direction: column-reverse;
    }
                
  • flex-wrap: nowrap;

    Prevents flex items from wrapping to a new line.

    
    .container {
      flex-wrap: nowrap;
    }
                
  • flex-wrap: wrap;

    Allows flex items to wrap onto multiple lines if needed.

    
    .container {
      flex-wrap: wrap;
    }
                
  • flex-wrap: wrap-reverse;

    Reverses the wrapping direction of flex items.

    
    .container {
      flex-wrap: wrap-reverse;
    }
                
  • flex-flow: row nowrap;

    Shorthand for setting flex-direction and flex-wrap.

    
    .container {
      flex-flow: row nowrap;
    }
                

Flexbox Properties II

  • justify-content: flex-start;

    Aligns flex items at the start of the main axis.

    
    .container {
      justify-content: flex-start;
    }
                
  • justify-content: flex-end;

    Aligns flex items at the end of the main axis.

    
    .container {
      justify-content: flex-end;
    }
                
  • justify-content: center;

    Aligns flex items at the center of the main axis.

    
    .container {
      justify-content: center;
    }
                
  • justify-content: space-between;

    Distributes flex items evenly with space between them.

    
    .container {
      justify-content: space-between;
    }
                
  • justify-content: space-around;

    Distributes flex items evenly with space around them.

    
    .container {
      justify-content: space-around;
    }
                
  • justify-content: space-evenly;

    Distributes flex items evenly with equal space around them.

    
    .container {
      justify-content: space-evenly;
    }
                
  • align-items: stretch;

    Stretches flex items to fill the container's cross-axis.

    
    .container {
      align-items: stretch;
    }
                
  • align-items: flex-start;

    Aligns flex items at the start of the cross axis.

    
    .container {
      align-items: flex-start;
    }
                
  • align-items: flex-end;

    Aligns flex items at the end of the cross axis.

    
    .container {
      align-items: flex-end;
    }
                
  • align-items: center;

    Aligns flex items at the center of the cross axis.

    
    .container {
      align-items: center;
    }
                

Flexbox Properties III

  • align-items: baseline;

    Aligns flex items such that their baselines align.

    
    .container {
      align-items: baseline;
    }
                
  • align-content: stretch;

    Stretches flex lines to fill the container.

    
    .container {
      align-content: stretch;
    }
                
  • align-content: flex-start;

    Aligns flex lines at the start of the cross axis.

    
    .container {
      align-content: flex-start;
    }
                
  • align-content: flex-end;

    Aligns flex lines at the end of the cross axis.

    
    .container {
      align-content: flex-end;
    }
                
  • align-content: center;

    Aligns flex lines at the center of the cross axis.

    
    .container {
      align-content: center;
    }
                
  • align-content: space-between;

    Distributes flex lines evenly with space between them.

    
    .container {
      align-content: space-between;
    }
                
  • align-content: space-around;

    Distributes flex lines evenly with space around them.

    
    .container {
      align-content: space-around;
    }
                
  • order: ;

    Specifies the order of a flex item.

    
    .item {
      order: 2;
    }
                
  • flex-grow: ;

    Specifies how much a flex item can grow relative to the rest.

    
    .item {
      flex-grow: 1;
    }
                
  • flex-shrink: ;

    Specifies how much a flex item can shrink relative to the rest.

    
    .item {
      flex-shrink: 0;
    }
                
  • flex-basis: | auto;

    Specifies the initial size of a flex item.

    
    .item {
      flex-basis: 100px;
    }
                
  • flex: ;

    Shorthand for flex-grow, flex-shrink, and flex-basis.

    
    .item {
      flex: 1 0 auto;
    }
                

Grid

  • display: grid;

    Defines a grid container.

    
    .example {
      display: grid;
    }
                
  • grid-template-columns

    Defines the columns of the grid with a space-separated list of values.

    
    .example {
      grid-template-columns: 100px 200px;
    }
                
  • grid-template-rows

    Defines the rows of the grid with a space-separated list of values.

    
    .example {
      grid-template-rows: 100px 200px;
    }
                
  • grid-template-areas

    Specifies named grid areas.

    
    .example {
      grid-template-areas: 
        "header header"
        "sidebar content"
        "footer footer";
    }
                
  • grid-gap

    Specifies the gap between rows and columns.

    
    .example {
      grid-gap: 10px;
    }
                

Backgrounds

  • background-color

    Specifies the background color of an element.

    
    .example {
      background-color: #ff0000;
    }
                
  • background-image

    Specifies one or more background images for an element.

    
    .example {
      background-image: url('image.jpg');
    }
                
  • background-repeat

    Defines how background images are repeated.

    
    .example {
      background-repeat: no-repeat;
    }
                
  • background-position

    Specifies the position of the background images.

    
    .example {
      background-position: center;
    }
                
  • background-size

    Specifies the size of the background images.

    
    .example {
      background-size: cover;
    }
                

Borders

  • border

    Sets the width, style, and color of the border.

    
    .example {
      border: 1px solid #000;
    }
                
  • border-width

    Specifies the width of the border.

    
    .example {
      border-width: 2px;
    }
                
  • border-style

    Specifies the style of the border.

    
    .example {
      border-style: dashed;
    }
                
  • border-color

    Specifies the color of the border.

    
    .example {
      border-color: red;
    }
                
  • border-radius

    Defines the radius of the border's corners.

    
    .example {
      border-radius: 5px;
    }
                

Colors

  • color

    Sets the color of the text.

    
    .example {
      color: #ff0000;
    }
                
  • background-color

    Sets the background color of an element.

    
    .example {
      background-color: #00ff00;
    }
                

Fonts

  • font-family

    Specifies the font family for the text.

    
    .example {
      font-family: 'Arial', sans-serif;
    }
                
  • font-size

    Specifies the size of the font.

    
    .example {
      font-size: 16px;
    }
                
  • font-weight

    Specifies the weight of the font.

    
    .example {
      font-weight: bold;
    }
                
  • font-style

    Specifies the style of the font.

    
    .example {
      font-style: italic;
    }
                
  • font-variant

    Specifies whether or not a text should be displayed in a small-caps font.

    
    .example {
      font-variant: small-caps;
    }
                

Text

  • text-align

    Specifies the horizontal alignment of text.

    
    .example {
      text-align: center;
    }
                
  • text-decoration

    Specifies the decoration added to text.

    
    .example {
      text-decoration: underline;
    }
                
  • text-transform

    Controls the capitalization of text.

    
    .example {
      text-transform: uppercase;
    }
                
  • letter-spacing

    Sets the space between characters in a text.

    
    .example {
      letter-spacing: 2px;
    }
                
  • line-height

    Specifies the height of a line.

    
    .example {
      line-height: 1.5;
    }
                

Transitions

  • transition

    A shorthand property for transition-property, transition-duration, transition-timing-function, and transition-delay.

    
    .example {
      transition: all 0.3s ease;
    }
                
  • transition-property

    Specifies the name of the CSS property the transition effect is for.

    
    .example {
      transition-property: background-color;
    }
                
  • transition-duration

    Defines how many seconds or milliseconds a transition effect takes to complete.

    
    .example {
      transition-duration: 0.5s;
    }
                
  • transition-timing-function

    Specifies the speed curve of the transition effect.

    
    .example {
      transition-timing-function: linear;
    }
                
  • transition-delay

    Defines when the transition effect will start.

    
    .example {
      transition-delay: 1s;
    }
                

Animations

  • animation

    A shorthand property for all the animation properties.

    
    .example {
      animation: slide 2s forwards;
    }
                
  • animation-name

    Specifies the name of the @keyframes animation.

    
    .example {
      animation-name: slide;
    }
                
  • animation-duration

    Specifies how many seconds or milliseconds an animation takes to complete one cycle.

    
    .example {
      animation-duration: 2s;
    }
                
  • animation-timing-function

    Specifies the speed curve of the animation.

    
    .example {
      animation-timing-function: ease;
    }
                
  • animation-delay

    Specifies when the animation will start.

    
    .example {
      animation-delay: 1s;
    }
                
  • animation-iteration-count

    Specifies the number of times an animation should be played.

    
    .example {
      animation-iteration-count: infinite;
    }
                
  • animation-direction

    Specifies whether or not the animation should play in reverse on alternate cycles.

    
    .example {
      animation-direction: alternate;
    }
                

Transforms

  • transform

    Applies a 2D or 3D transformation to an element.

    
    .example {
      transform: rotate(45deg);
    }
                
  • transform-origin

    Specifies the origin for the transformation.

    
    .example {
      transform-origin: top left;
    }
                
  • transform-style

    Specifies how nested elements are rendered in 3D space.

    
    .example {
      transform-style: preserve-3d;
    }
                
  • perspective

    Defines the perspective from which the viewer sees the 3D transformed elements.

    
    .example {
      perspective: 1000px;
    }
                
  • perspective-origin

    Defines the origin for the perspective property.

    
    .example {
      perspective-origin: top left;
    }
                

Filters

  • filter

    Applies graphical effects like blur or color shift to an element.

    
    .example {
      filter: blur(5px);
    }
                
  • blur

    Applies a Gaussian blur to the element.

    
    .example {
      filter: blur(10px);
    }
                
  • brightness

    Adjusts the brightness of the element.

    
    .example {
      filter: brightness(0.5);
    }
                
  • contrast

    Adjusts the contrast of the element.

    
    .example {
      filter: contrast(200%);
    }
                
  • drop-shadow

    Applies a drop shadow effect to the element.

    
    .example {
      filter: drop-shadow(2px 2px 2px black);
    }
                

Layout

  • display

    Specifies the display behavior (the type of rendering box) of an element.

    
    .example {
      display: block;
    }
                
  • position

    Specifies the type of positioning method used for an element.

    
    .example {
      position: absolute;
    }
                
  • top, right, bottom, left

    Specifies the position of a positioned element.

    
    .example {
      top: 10px;
      right: 20px;
    }
                
  • float

    Specifies whether an element should float to the left, right, or not at all.

    
    .example {
      float: left;
    }
                
  • clear

    Specifies on which sides of an element floating elements are not allowed to float.

    
    .example {
      clear: both;
    }
                

Pseudo-classes

  • :hover

    Applies when the user designates an element (with some pointing device), but does not activate it.

    
    .example:hover {
      color: blue;
    }
                
  • :focus

    Applies while an element has the focus (accepts keyboard or mouse events, or other forms of input).

    
    .example:focus {
      outline: 2px solid blue;
    }
                
  • :active

    Applies while an element is being activated by the user (e.g., between the times the user presses the mouse button and releases it).

    
    .example:active {
      background-color: yellow;
    }
                
  • :nth-child(n)

    Matches elements based on their position in a group of siblings.

    
    .example:nth-child(2) {
      color: red;
    }
                
  • :nth-of-type(n)

    Matches elements of a given type, based on their position among a group of siblings.

    
    .example:nth-of-type(3) {
      color: green;
    }
                

Pseudo-elements

  • ::before

    Inserts content before the content of an element.

    
    .example::before {
      content: "Note: ";
      color: red;
    }
                
  • ::after

    Inserts content after the content of an element.

    
    .example::after {
      content: "!";
      color: blue;
    }
                
  • ::first-letter

    Styles the first letter of the first line of a block-level element.

    
    .example::first-letter {
      font-size: 2em;
      color: green;
    }
                
  • ::first-line

    Styles the first line of a block-level element.

    
    .example::first-line {
      font-weight: bold;
    }
                

Media Queries

  • @media

    Applies styles based on the result of one or more media queries.

    
    @media (max-width: 600px) {
      .example {
        background-color: lightblue;
      }
    }
                
  • media features

    Specifies the conditions of a media query, such as screen width, resolution, or orientation.

    
    @media (orientation: landscape) {
      .example {
        background-color: lightgreen;
      }
    }
                

Units

  • px (pixels)

    A pixel is a relative unit, representing a dot on the screen.

    
    .example {
      font-size: 16px;
    }
                
  • em

    Relative to the font-size of the element (2em means 2 times the size of the current font).

    
    .example {
      margin: 1em;
    }
                
  • rem

    Relative to the font-size of the root element.

    
    .example {
      padding: 1rem;
    }
                
  • %

    Defines a length as a percentage relative to another value, typically the parent element's length.

    
    .example {
      width: 50%;
    }
                
  • vw, vh

    Relative to 1% of the width (vw) or height (vh) of the viewport.

    
    .example {
      height: 50vh;
    }
                

Sizing

  • width

    Sets the width of an element.

    
    .example {
      width: 100px;
    }
                
  • height

    Sets the height of an element.

    
    .example {
      height: 200px;
    }
                
  • max-width

    Sets the maximum width of an element.

    
    .example {
      max-width: 100%;
    }
                
  • max-height

    Sets the maximum height of an element.

    
    .example {
      max-height: 500px;
    }
                
  • min-width

    Sets the minimum width of an element.

    
    .example {
      min-width: 50px;
    }
                
  • min-height

    Sets the minimum height of an element.

    
    .example {
      min-height: 100px;
    }
                

Margins

  • margin

    Sets the margin space on all sides of an element.

    
    .example {
      margin: 20px;
    }
                
  • margin-top

    Sets the top margin of an element.

    
    .example {
      margin-top: 10px;
    }
                
  • margin-right

    Sets the right margin of an element.

    
    .example {
      margin-right: 15px;
    }
                
  • margin-bottom

    Sets the bottom margin of an element.

    
    .example {
      margin-bottom: 5px;
    }
                
  • margin-left

    Sets the left margin of an element.

    
    .example {
      margin-left: 30px;
    }
                

Padding

  • padding

    Sets the padding space on all sides of an element.

    
    .example {
      padding: 20px;
    }
                
  • padding-top

    Sets the top padding of an element.

    
    .example {
      padding-top: 10px;
    }
                
  • padding-right

    Sets the right padding of an element.

    
    .example {
      padding-right: 15px;
    }
                
  • padding-bottom

    Sets the bottom padding of an element.

    
    .example {
      padding-bottom: 5px;
    }
                
  • padding-left

    Sets the left padding of an element.

    
    .example {
      padding-left: 30px;
    }
                

Overflow

  • overflow

    Specifies what happens if content overflows an element's box.

    
    .example {
      overflow: hidden;
    }
                
  • overflow-x

    Specifies what happens with the left/right edges of the content if it overflows the element's content area.

    
    .example {
      overflow-x: scroll;
    }
                
  • overflow-y

    Specifies what happens with the top/bottom edges of the content if it overflows the element's content area.

    
    .example {
      overflow-y: auto;
    }
                

Float and Clear

  • float

    Specifies whether an element should float to the left, right, or none.

    
    .example {
      float: left;
    }
                
  • clear

    Specifies what elements can float beside the cleared element and on which sides.

    
    .example {
      clear: both;
    }
                

Z-index

  • z-index

    Specifies the stack order of positioned elements.

    
    .example {
      z-index: 10;
    }
                

Lists

  • list-style

    Sets all the list properties in one declaration.

    
    .example {
      list-style: square inside;
    }
                
  • list-style-type

    Specifies the type of list-item marker.

    
    .example {
      list-style-type: disc;
    }
                
  • list-style-position

    Specifies the position of the list-item marker.

    
    .example {
      list-style-position: outside;
    }
                
  • list-style-image

    Specifies an image as the list-item marker.

    
    .example {
      list-style-image: url('image.png');
    }
                

Tables

  • border-collapse

    Sets whether the table borders should be collapsed into a single border or separated.

    
    .example {
      border-collapse: collapse;
    }
                
  • border-spacing

    Sets the distance between the borders of adjacent cells.

    
    .example {
      border-spacing: 10px;
    }
                
  • table-layout

    Sets the layout algorithm to be used for the table.

    
    .example {
      table-layout: fixed;
    }
                
  • caption-side

    Specifies the placement of the table caption.

    
    .example {
      caption-side: bottom;
    }
                
  • empty-cells

    Sets whether or not to display borders on empty cells.

    
    .example {
      empty-cells: hide;
    }
                

Tables

  • border-collapse

    Sets whether the table borders should be collapsed into a single border or separated.

    
    .example {
      border-collapse: collapse;
    }
                
  • border-spacing

    Sets the distance between the borders of adjacent cells.

    
    .example {
      border-spacing: 10px;
    }
                
  • table-layout

    Sets the layout algorithm to be used for the table.

    
    .example {
      table-layout: fixed;
    }
                
  • caption-side

    Specifies the placement of the table caption.

    
    .example {
      caption-side: bottom;
    }
                
  • empty-cells

    Sets whether or not to display borders on empty cells.

    
    .example {
      empty-cells: hide;
    }
                

Cursor

  • cursor

    Specifies the mouse cursor to be displayed when pointing over an element.

    
    .example {
      cursor: pointer;
    }
                

Shadows

  • box-shadow

    Adds shadow effects around an element's frame.

    
    .example {
      box-shadow: 10px 10px 5px grey;
    }
                
  • text-shadow

    Adds shadow effects to text.

    
    .example {
      text-shadow: 2px 2px 5px red;
    }
                

Outlines

  • outline

    Sets all the outline properties in a single declaration.

    
    .example {
      outline: 2px solid blue;
    }
                
  • outline-width

    Sets the width of the outline.

    
    .example {
      outline-width: thick;
    }
                
  • outline-style

    Sets the style of the outline.

    
    .example {
      outline-style: dashed;
    }
                
  • outline-color

    Sets the color of the outline.

    
    .example {
      outline-color: red;
    }
                

Opacity

  • opacity

    Sets the opacity level for an element.

    
    .example {
      opacity: 0.5;
    }
                

Content

  • content

    Inserts content before or after an element.

    
    .example::before {
      content: 'Prefix ';
    }
    .example::after {
      content: ' Suffix';
    }
                

Counters

  • counter-reset

    Creates or resets a counter.

    
    .example {
      counter-reset: section;
    }
                
  • counter-increment

    Increments the value of a counter.

    
    .example {
      counter-increment: section;
    }
                
  • content

    Uses a counter value as content.

    
    .example::before {
      content: counter(section) '. ';
    }
                

Columns

  • column-count

    Specifies the number of columns an element should be divided into.

    
    .example {
      column-count: 3;
    }
                
  • column-gap

    Specifies the gap between the columns.

    
    .example {
      column-gap: 15px;
    }
                
  • column-rule

    Specifies a rule between columns.

    
    .example {
      column-rule: 1px solid black;
    }
                

User Interface

  • appearance

    Allows you to make an element look like a standard user interface element.

    
    .example {
      appearance: none;
    }
                
  • box-sizing

    Defines how the width and height of an element are calculated.

    
    .example {
      box-sizing: border-box;
    }
                
  • caret-color

    Sets the color of the text cursor (caret).

    
    .example {
      caret-color: red;
    }
                

Variables (Custom Properties)

  • --variable-name

    Defines a custom property (variable).

    
    :root {
      --main-bg-color: brown;
    }
    .example {
      background-color: var(--main-bg-color);
    }
                

Functions

  • calc()

    Performs calculations to determine CSS property values.

    
    .example {
      width: calc(100% - 50px);
    }
                
  • var()

    Used to insert the value of a custom property.

    
    .example {
      color: var(--main-color);
    }
                

Values and Units

  • px, em, rem

    Common units for specifying dimensions.

    
    .example {
      width: 100px;
      padding: 2em;
      font-size: 1rem;
    }
                
  • %, vh, vw

    Relative units for specifying dimensions.

    
    .example {
      width: 50%;
      height: 100vh;
      font-size: 10vw;
    }
                

Typography

  • font-family

    Specifies the font for an element.

    
    .example {
      font-family: Arial, sans-serif;
    }
                
  • font-size

    Specifies the font size for an element.

    
    .example {
      font-size: 16px;
    }
                
  • font-weight

    Specifies the weight (or boldness) of the font.

    
    .example {
      font-weight: bold;
    }
                
  • line-height

    Specifies the height of a line of text.

    
    .example {
      line-height: 1.5;
    }
                

Print

  • @media print

    Specifies print-specific styles.

    
    @media print {
      .example {
        font-size: 12pt;
        color: black;
      }
    }
                

CSS Resets

  • CSS Reset

    Resets the default styling of all HTML elements to a consistent baseline.

    
    /* Example of a simple CSS reset */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    html, body {
      height: 100%;
    }
                

Created by Arsalan Khan | CSS_Cheat_Sheet v1.0 | © 2024