color
Sets the color of text.
p {
color: blue;
}
background-color
Sets the background color of an element.
div {
background-color: #f0f0f0;
}
font-family
Specifies the font for text.
body {
font-family: Arial, sans-serif;
}
font-size
Sets the size of the font.
h1 {
font-size: 24px;
}
font-weight
Defines the thickness of characters.
strong {
font-weight: bold;
}
text-align
Aligns the text within an element.
.center-text {
text-align: center;
}
width
and height
Sets the width and height of an element.
.box {
width: 200px;
height: 100px;
}
padding
Creates space inside an element, between its content and its border.
.padded {
padding: 10px;
}
margin
Creates space outside an element.
.spaced {
margin: 20px;
}
border
Adds a border around an element.
.bordered {
border: 1px solid black;
}
display
Specifies how an element should be displayed.
span {
display: inline-block;
}
visibility
Determines whether an element is visible or hidden.
.hidden {
visibility: hidden;
}
position
Specifies the positioning method for an element.
.relative {
position: relative;
top: 10px;
left: 20px;
}
z-index
Controls the stacking order of elements.
.top-layer {
z-index: 1;
}
display: flex
Creates a flex container.
.container {
display: flex;
}
flex-direction
Defines the direction of flex items.
.column {
flex-direction: column;
}
justify-content
Aligns flex items along the main axis.
.spread {
justify-content: space-between;
}
display: grid
Creates a grid container.
.grid-container {
display: grid;
}
grid-template-columns
Defines the columns of the grid.
.three-column {
grid-template-columns: 1fr 1fr 1fr;
}
transition
Adds smooth transitions to property changes.
button {
transition: background-color 0.3s ease;
}
transform
Applies 2D or 3D transformations to an element.
.rotated {
transform: rotate(45deg);
}
@media
Applies different styles for different screen sizes.
@media screen and (max-width: 600px) {
body {
font-size: 14px;
}
}
Select elements based on their attributes or attribute values.
/* Selects inputs with a "type" attribute of "text" */
input[type="text"] {
border: 1px solid #ccc;
}
/* Selects anchors with an "href" starting with "https" */
a[href^="https"] {
color: green;
}
Target specific states or parts of elements.
/* Style the first line of a paragraph */
p::first-line {
font-weight: bold;
}
/* Style odd rows in a table */
tr:nth-child(odd) {
background-color: #f2f2f2;
}
Define reusable values that can be used throughout your stylesheet.
:root {
--primary-color: #3498db;
--secondary-color: #2ecc71;
}
.button {
background-color: var(--primary-color);
color: white;
}
box-sizing
Changes how the total width and height of elements are calculated.
* {
box-sizing: border-box;
}
clip-path
Creates a clipping region that sets what part of an element should be shown.
.clip-circle {
clip-path: circle(50% at center);
}
flex-grow
, flex-shrink
, and flex-basis
Fine-tune how flex items grow and shrink.
.flex-item {
flex: 1 0 200px; /* grow shrink basis */
}
align-self
Aligns individual flex items.
.special-item {
align-self: flex-end;
}
grid-template-areas
Defines named grid areas.
.container {
display: grid;
grid-template-areas:
"header header"
"sidebar content"
"footer footer";
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.content { grid-area: content; }
.footer { grid-area: footer; }
minmax()
Sets a size range for grid tracks.
.grid {
grid-template-columns: repeat(3, minmax(100px, 1fr));
}
Create complex, multi-step animations.
@keyframes slide-in {
0% { transform: translateX(-100%); }
100% { transform: translateX(0); }
}
.animated {
animation: slide-in 0.5s ease-out;
}
Fine-tune your animations.
.bounce {
animation-name: bounce;
animation-duration: 1s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-direction: alternate;
}
Create non-rectangular shapes for text wrapping.
.circle-text {
shape-outside: circle(50%);
width: 200px;
height: 200px;
float: left;
}
Apply graphical effects like blur or color shifting to elements.
.blurred {
filter: blur(5px);
}
.vintage {
filter: sepia(0.5) contrast(1.2) brightness(1.1);
}
Allows grid items to inherit the grid of their parent.
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.grid-item {
display: grid;
grid-template-columns: subgrid;
}
Write direction-agnostic styles for better internationalization.
.box {
margin-inline-start: 1em;
padding-block-end: 2em;
}
Improve performance by isolating parts of the page.
.widget {
contain: content;
}
next -> Css Display