CSS 3 Cheat Sheet Quick Reference
CSS 3 Cheat Sheet Quick Reference
CSS 3
This is a quick reference cheat sheet for CSS goodness, listing selector syntax, properties, units and other useful bits of information.
# Getting Started
- Introduction
CSS is rich in capabilities and is more than simply laying out pages.
External stylesheet
Internal stylesheet
<style>
body {
background-color: linen;
}
</style>
Inline styles
Add class
https://quickref.me/css3.html 1/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
<div class="classname"></div>
<div class="class1 ... classn"></div>
!important
.post-title {
color: blue !important;
}
Selector
h1 { }
#job-title { }
div.hero { }
div > p { }
See: Selectors
Text color
color: #2a2aff;
color: green;
color: rgb(34, 12, 64, 0.6);
color: hsla(30 100% 50% / 0.6);
See: Colors
Background
background-color: blue;
background-image: url("nyan-cat.gif");
background-image: url("../image.png");
See: Backgrounds
Font
.page-title {
font-weight: bold;
font-size: 30px;
font-family: "Courier New";
}
See: Fonts
Position
.box {
position: relative;
top: 20px;
left: 20px;
}
Crea impactantes contenidos
de marca con la ayuda de
nuestro Creative Assistant
See also: Position basado en IA. Empieza ya.
SPONSORED BY MAILCHIMP
Animation
https://quickref.me/css3.html 2/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
Comment
/* This is a
multi-line comment */
Flex layout
div {
display: flex;
justify-content: center;
}
div {
display: flex;
justify-content: flex-start;
}
Grid layout
#container {
display: grid;
grid: repeat(2, 60px) / auto-flow 80px;
}
counter-set: subsection;
counter-increment: subsection;
counter-reset: subsection 0;
:root {
--bg-color: brown;
}
element {
background-color: var(--bg-color);
}
https://quickref.me/css3.html 3/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
# CSS Selectors
- Examples
Groups Selector
h1, h2 {
color: red;
}
Chaining Selector
h3.section-heading {
color: blue;
}
Attribute Selector
div[attribute="SomeValue"] {
background-color: red;
}
p:first-child {
font-weight: bold;
}
No Children Selector
.box:empty {
background: lime;
height: 80px;
width: 80px;
}
Basic
* All elements
Combinators
https://quickref.me/css3.html 4/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
Attribute selectors
Pseudo classes
https://quickref.me/css3.html 5/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
# CSS Fonts
Properties
font-family: <font>
font-size: <size>
letter-spacing: <size>
line-height: <number>
https://quickref.me/css3.html 6/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
Shorthand
Example
Case
/* Hello */
text-transform: capitalize;
/* HELLO */
text-transform: uppercase;
/* hello */
text-transform: lowercase;
@font-face
@font-face {
font-family: 'Glegoo';
src: url('../Glegoo.woff');
}
# CSS Colors
Named color
color: red;
color: orange;
color: tan;
color: rebeccapurple;
Hexadecimal color
color: #090;
color: #009900;
color: #090a;
color: #009900aa;
rgb() Colors
https://quickref.me/css3.html 7/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
HSL Colors
Other
color: inherit;
color: initial;
color: unset;
color: transparent;
# CSS Backgrounds
Properties
background: (Shorthand)
background-image: url(...)
left/center/right
background-position:
top/center/bottom
background-size: cover X Y
border-box
background-clip: padding-box
content-box
no-repeat
background-repeat: repeat-x
repeat-y
background-attachment: scroll/fixed/local
Shorthand
Examples
https://quickref.me/css3.html 8/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
.column {
max-width: 200px;
width: 500px;
}
Margin / Padding
.block-one {
margin: 20px;
padding: 10px;
}
Box-sizing
.container {
box-sizing: border-box;
}
Visibility
.invisible-elements {
visibility: hidden;
}
Auto keyword
div {
margin: auto;
}
Overflow
.small-block {
overflow: scroll;
}
# CSS Animation
Shorthand
https://quickref.me/css3.html 9/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
Properties
animation: (shorthand)
animation-name: <name>
animation-duration: <time>ms
animation-delay: <time>ms
Example
Javascript Event
# CSS Flexbox
Simple example
.container {
display: flex;
Crea impactantes contenidos
} de marca con la ayuda de
nuestro Creative Assistant
basado en IA. Empieza ya.
.container > div { SPONSORED BY MAILCHIMP
flex: 1 1 auto;
}
https://quickref.me/css3.html 10/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
- Container
.container {
display: flex;
display: inline-flex;
- Child
/* This: */
flex: 1 0 auto;
/* Is equivalent to this: */
flex-grow: 1;
flex-shrink: 0;
flex-basis: auto;
order: 1;
https://quickref.me/css3.html 11/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
.container > div {
width: 100px;
height: 100px;
margin: auto;
}
.container {
display: flex;
/* vertical */
align-items: center;
/* horizontal */
justify-content: center;
}
Reordering
Mobile layout
.container {
display: flex;
flex-direction: column;
}
Table-like
.container {
display: flex;
}
Vertical
https://quickref.me/css3.html 12/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
.container {
align-items: center;
}
#grid-container {
display: grid;
width: 100px;
grid-template-columns: 20px 20% 60%;
}
fr Relative Unit
.grid {
display: grid;
width: 100px;
grid-template-columns: 1fr 60px 1fr;
}
Grid Gap
#grid-container {
display: block;
}
- CSS grid-row
CSS syntax:
Example
Crea impactantes contenidos
.item { de marca con la ayuda de
nuestro Creative Assistant
grid-row: 1 / span 2;
basado en IA. Empieza ya.
} SPONSORED BY MAILCHIMP
https://quickref.me/css3.html 13/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
#grid-container {
display: inline-grid;
}
minmax() Function
.grid {
display: grid;
grid-template-columns: 100px minmax(100px, 500px) 100px;
}
CSS syntax:
grid-row-start: auto|row-line;
grid-row-end: auto|row-line|span n;
Example
grid-row-start: 2;
grid-row-end: span 2;
CSS grid-row-gap
grid-row-gap: length;
CSS grid-area
.item1 {
grid-area: 2 / 1 / span 2 / span 3;
}
Justify Items
#container {
display: grid;
justify-items: center;
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-gap: 10px;
}
CSS grid-template-areas
.item {
grid-area: nav;
}
.grid-container {
display: grid;
grid-template-areas:
'nav nav . .'
Crea impactantes contenidos
'nav nav . .'; de marca con la ayuda de
} nuestro Creative Assistant
basado en IA. Empieza ya.
SPONSORED BY MAILCHIMP
Justify Self
https://quickref.me/css3.html 14/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
#grid-container {
display: grid;
justify-items: start;
}
.grid-items {
justify-self: end;
}
Align Items
#container {
display: grid;
align-items: start;
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-gap: 10px;
}
:root {
--first-color: #16f;
--second-color: #ff7;
}
Variable Usage
#firstParagraph {
background-color: var(--first-color);
color: var(--second-color);
}
Counter
/* Set "my-counter" to 0 */
counter-set: my-counter;
/* Increment "my-counter" by 1 */
counter-increment: my-counter;
/* Decrement "my-counter" by 1 */
counter-increment: my-counter -1;
https://quickref.me/css3.html 15/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
Using counters
h3::before {
counter-increment: section;
content: "Section." counter(section);
}
ol {
counter-reset: section;
list-marker-type: none;
}
li::before {
counter-increment: section;
content: counters(section, ".") " ";
}
# Css 3 tricks
Scrollbar smooth
html {
scroll-behavior: smooth;
}
# Also see
CSS selectors cheatsheet (frontend30.com)
MDN: Using CSS flexbox
Ultimate flexbox cheatsheet
GRID: A simple visual cheatsheet
CSS Tricks: A Complete Guide to Grid
Browser support
https://quickref.me/css3.html 16/17
3/7/23, 13:25 CSS 3 Cheat Sheet & Quick Reference
SEE MORE
Related Cheatsheet
Recent Cheatsheet
https://quickref.me/css3.html 17/17