CSS Reference
Basic Selectors
* {} → The universal selector selects ALL elements on the page.
html {} → The html selector targets the entire HTML document (root element).
body {} → The body selector targets all visible page content.
p {} → The p selector targets all paragraph elements.
h1 {} → The h1 selector targets all level-1 headings.
h2 {} → The h2 selector targets all level-2 headings.
h3 {} → The h3 selector targets all level-3 headings.
h4 {} → The h4 selector targets all level-4 headings.
h5 {} → The h5 selector targets all level-5 headings.
h6 {} → The h6 selector targets all level-6 headings.
a {} → The a selector targets all hyperlinks.
img {} → The img selector targets all images.
div {} → The div selector targets all div containers.
span {} → The span selector targets all span elements.
Class and ID Selectors
.className {} → The class selector targets elements with a specific class.
#idName {} → The ID selector targets the element with a specific ID.
div.box {} → Targets div elements that have class "box".
p.note {} → Targets paragraphs with class "note".
Grouping and Combination
h1, h2, h3 {} → Targets multiple selectors at once.
div p {} → Descendant selector: targets p inside div.
div > p {} → Child selector: targets direct p children of div.
h1 + p {} → Adjacent sibling: p immediately after h1.
h1 ~ p {} → General sibling: all p after h1.
Pseudo-classes
a:hover {} → Styles link when mouse hovers over it.
a:active {} → Styles link while being clicked.
a:visited {} → Styles visited links.
input:focus {} → Styles input when focused.
li:first-child {} → First child element.
li:last-child {} → Last child element.
li:nth-child(2) {} → Second child element.
Pseudo-elements
p::first-letter {} → Styles the first letter of a paragraph.
p::first-line {} → Styles the first line of text.
::selection {} → Styles selected text.
::before {} → Inserts content before element.
::after {} → Inserts content after element.
Common Properties
color: ; → Sets text color.
background: ; → Sets background.
background-color: ; → Sets background color.
font-size: ; → Sets text size.
font-family: ; → Sets font type.
font-weight: ; → Sets boldness.
text-align: ; → Aligns text.
text-decoration: ; → Underline/line-through/etc.
margin: ; → Outer spacing.
padding: ; → Inner spacing.
border: ; → Border around element.
border-radius: ; → Rounded corners.
width: ; → Element width.
height: ; → Element height.
display: ; → Layout type (block, inline, flex, grid).
position: ; → Positioning method.
top: ; → Top offset.
left: ; → Left offset.
right: ; → Right offset.
bottom: ; → Bottom offset.
overflow: ; → Content overflow behavior.
z-index: ; → Stacking order.
opacity: ; → Transparency level.
box-shadow: ; → Shadow effect.
transition: ; → Smooth animation.
transform: ; → Move/scale/rotate element.
cursor: ; → Mouse cursor style.