css cheat sheet, css syntax reference, css selectors list, css flexbox guide, css grid layout, css colors and typography, css positioning examples, css border and background, css animation and transition, css box model
css cheat sheet, css syntax reference, css selectors list, css flexbox guide, css grid layout, css colors and typography, css positioning examples, css border and background, css animation and transition, css box model

CSS Cheat Sheet — Complete CSS3 Selectors, Properties, and Layout Examples

CSS Cheat Sheet — Complete CSS3 Syntax, Selectors & Layout Examples

Cascading Style Sheets (CSS) is the language used to style HTML — controlling layout, colors, typography, and overall design. This CSS Cheat Sheet provides all essential CSS properties, examples, and modern layout techniques like Flexbox and Grid for quick reference and learning.


What is CSS?

CSS (Cascading Style Sheets) defines how HTML elements are displayed on screen, paper, or other media. It separates content (HTML) from presentation (CSS), improving flexibility and maintainability.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  color: blue;
  text-align: center;
}
p {
  font-size: 18px;
}
</style>
</head>
<body>
<h1>Hello CSS!</h1>
<p>This paragraph is styled using CSS.</p>
</body>
</html>

CSS Syntax

CSS consists of a selector and a declaration block.

selector {
  property: value;
}

Example:

p {
  color: red;
  font-size: 16px;
}

CSS Selectors

Selectors target HTML elements for styling.

Selector TypeExampleDescription
Element SelectorpSelects all <p> tags
Class Selector.boxSelects elements with class “box”
ID Selector#headerSelects element with id “header”
Universal Selector*Selects all elements
Group Selectorh1, h2, h3Groups multiple selectors
Descendant Selectordiv pSelects <p> inside <div>
Child Selectordiv > pSelects direct child elements
Attribute Selectorinput[type="text"]Selects elements with specific attribute
Pseudo-Classa:hoverStyles on hover
Pseudo-Elementp::first-lineStyles first line of paragraph

CSS Colors and Backgrounds

PropertyExampleDescription
colorcolor: blue;Text color
background-colorbackground-color: #f0f0f0;Background color
background-imagebackground-image: url("bg.jpg");Sets background image
background-sizebackground-size: cover;Adjusts image size
opacityopacity: 0.8;Sets transparency

Example:

body {
  background: linear-gradient(to right, #00c6ff, #0072ff);
  color: white;
}

CSS Box Model

Every element in CSS is a box made up of content, padding, border, and margin.

PropertyExampleDescription
width, heightwidth: 100px;Element dimensions
paddingpadding: 10px;Inner spacing
borderborder: 1px solid #000;Border around element
marginmargin: 15px;Outer spacing
box-sizingbox-sizing: border-box;Includes padding and border in total width

Example:

div {
  width: 200px;
  padding: 10px;
  border: 2px solid gray;
  margin: 15px;
  box-sizing: border-box;
}

CSS Typography

PropertyExampleDescription
font-familyfont-family: Arial, sans-serif;Sets font
font-sizefont-size: 18px;Sets size
font-weightfont-weight: bold;Bold text
text-aligntext-align: center;Aligns text
line-heightline-height: 1.5;Sets line spacing
text-transformtext-transform: uppercase;Changes text case
letter-spacingletter-spacing: 2px;Space between letters
css cheat sheet, css syntax reference, css selectors list, css flexbox guide, css grid layout, css colors and typography, css positioning examples, css border and background, css animation and transition, css box model

CSS Borders, Margin, and Padding

PropertyExampleDescription
borderborder: 1px solid black;Adds border
border-radiusborder-radius: 10px;Rounds corners
marginmargin: 20px;Outer spacing
paddingpadding: 15px;Inner spacing

CSS Display and Positioning

PropertyExampleDescription
displaydisplay: block;Defines element display
positionposition: absolute;Positions element
top, left, right, bottomtop: 10px;Set position offsets
z-indexz-index: 10;Layer order
floatfloat: right;Floating element
clearclear: both;Control float behavior

Example:

.box {
  position: relative;
  top: 20px;
  left: 30px;
}

CSS Flexbox Layout

Flexbox simplifies alignment, spacing, and layout control.

Example:

.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
PropertyDescription
display: flexEnables flexbox
flex-directionDefines row or column layout
justify-contentHorizontal alignment
align-itemsVertical alignment
flex-wrapWrap items
align-contentAlign multiple lines

CSS Grid Layout

CSS Grid allows two-dimensional layouts.

Example:

.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
PropertyDescription
display: gridEnables grid
grid-template-columnsDefines columns
grid-template-rowsDefines rows
gapSpace between grid items
justify-itemsHorizontal alignment
align-itemsVertical alignment

CSS Animation and Transition

PropertyExampleDescription
transitiontransition: 0.3s ease;Smooth change
animation-nameanimation-name: fade;Animation name
animation-durationanimation-duration: 2s;Animation time

Example:

@keyframes fade {
  from {opacity: 0;}
  to {opacity: 1;}
}
.box {
  animation: fade 2s ease-in-out;
}

CSS Units and Measurements

UnitDescriptionExample
pxPixelswidth: 200px;
%Percentagewidth: 50%;
emRelative to parent font sizemargin: 2em;
remRelative to root font sizefont-size: 1.5rem;
vh, vwViewport height/widthheight: 100vh;

Internal Resources


FAQ – CSS Cheat Sheet

Q1: What is CSS used for?
CSS styles HTML elements, controlling layout, colors, and typography for beautiful web design.

Q2: What is the difference between inline, internal, and external CSS?

  • Inline CSS: inside HTML tags
  • Internal CSS: inside <style> in <head>
  • External CSS: linked .css file

Q3: What are Flexbox and Grid used for?
Flexbox handles one-dimensional layouts, while Grid is for complex two-dimensional layouts.

Q4: How can I center an element in CSS?
Using Flexbox:

display: flex;
justify-content: center;
align-items: center;

Q5: How to make a responsive layout?
Use media queries:

@media (max-width: 600px) {
  body { font-size: 14px; }
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments