CSS controls how your website looks — colors, spacing, fonts, layout, and more. You don't need to memorize any of this. Just understand the concepts and let your AI tool write the code.
💡 How to use this guide
Each section explains a CSS concept in plain English, shows you a live visual example, and gives you a ready-to-use promptyou can paste into your AI tool. You don't need to write CSS yourself.
Every element on a webpage is a box. Seriously — even text, images, and buttons are boxes. Understanding the layers of a box is the single most important CSS concept.
The actual stuff inside — your text, image, or button label.
🧠 Analogy: Think of it as the gift inside a package.
Space between your content and the border. Makes things feel less cramped.
🧠 Analogy: The bubble wrap around the gift — it adds breathing room inside the box.
Prompt your AI
“Add more padding inside the card so the text doesn't touch the edges”
The visible edge of the box. Can be thin, thick, colored, dashed, or invisible.
🧠 Analogy: The cardboard walls of the package.
Prompt your AI
“Add a light gray border around the card with rounded corners”
Space outside the border — the gap between this element and its neighbors.
🧠 Analogy: The space between packages on a shelf.
Prompt your AI
“Add more space between each card so they don't feel squished together”
👁️ See it in action
This confuses everyone at first. Here's the simple rule: padding = space inside, margin = space outside.
Pushes content away from the edges of its own box. The background color fills the padding area.
🧠 Analogy: Like the margins on a printed page — the text doesn't go to the edge of the paper.
Prompt your AI
“Increase the padding inside this button so the text has more breathing room”
Pushes the whole box away from other boxes around it. Margin is always transparent.
🧠 Analogy: Like the gap between picture frames on a wall.
Prompt your AI
“Add more margin below the heading to separate it from the paragraph”
👁️ See it in action
Font size controls how big or small your text appears. Bigger text grabs attention (headings), smaller text is for details (captions, labels).
The most straightforward unit — 16px is the default body text size in most browsers.
🧠 Analogy: Think of pixels like font sizes in Google Docs or Word.
Prompt your AI
“Make the heading text 36px and the body text 16px”
Big headings, medium subheadings, normal body text, small captions. This hierarchy helps readers scan your page.
🧠 Analogy: Like a newspaper — the headline is huge, subheadlines are medium, articles are normal size.
Prompt your AI
“Create a clear text hierarchy: page title should be the biggest, section titles medium, and body text normal size”
👁️ See it in action
12px — Fine print, captions
14px — Small text, labels
16px — Normal body text (default)
20px — Slightly larger, subheadings
24px — Section headings
36px — Big headings
Font weight is how thick or thin the letters are. Bold text stands out, light text feels elegant.
Weights go from 100 (ultra-thin) to 900 (ultra-thick). 400 is normal, 700 is bold.
🧠 Analogy: Think of it like pencil pressure — light, normal, heavy.
Prompt your AI
“Make the heading bold (700) and the body text normal weight (400)”
Headings are usually bold (600–800). Body text is normal (400). Use semi-bold (500–600) for things like navigation links or labels.
🧠 Analogy: Bold is for shouting, normal is for talking, light is for whispering.
Prompt your AI
“Make the navigation links semi-bold so they stand out without being too heavy”
👁️ See it in action
Light (300) — Thin and delicate
Normal (400) — Default body weight
Medium (500) — Slightly heavier
Semi-bold (600) — Stands out nicely
Bold (700) — Strong emphasis
Extra-bold (800) — Maximum impact
Text alignment controls whether your text sticks to the left, sits in the center, or pushes to the right.
Left is the default (and easiest to read for long text). Center works for headings, hero sections, and short bits of text. Right is rare — mostly for dates or numbers.
🧠 Analogy: Like choosing paragraph alignment in Google Docs.
Prompt your AI
“Center the hero heading and subtitle, but keep the article body text left-aligned”
👁️ See it in action
Colors set the mood of your site. You can change the color of text, backgrounds, borders, and more.
The color of your letters. Dark text on light backgrounds (or light text on dark backgrounds) is the key to readability.
🧠 Analogy: Like choosing your pen color.
Prompt your AI
“Make the heading text dark gray (#333) and the body text a softer gray (#666)”
Fills the entire box behind your content. Use soft colors for sections, bold colors for buttons.
🧠 Analogy: Like highlighting text with a marker — the marker color is the background.
Prompt your AI
“Give the pricing card a light purple background to make it stand out”
Colors are written as hex codes like #FF0000 (red) or #8B5CF6 (purple). Your AI tool handles this — just describe the color you want.
🧠 Analogy: Hex codes are like paint color codes at a hardware store.
Prompt your AI
“Use a warm purple (#8B5CF6) for the buttons and a soft pink (#FDF2F8) for the card background”
👁️ See it in action
Borders are the visible edges of a box. Rounded corners (border-radius) make things feel modern and friendly.
A border has three parts: thickness (1px, 2px), style (solid, dashed), and color (#e5e7eb).
🧠 Analogy: Like drawing a rectangle with a pen — you pick the pen thickness, line style, and color.
Prompt your AI
“Add a 1px solid light gray border around each card”
Border-radius rounds the corners. Small values = slightly rounded. Large values = pill-shaped. Very large = circle.
🧠 Analogy: Like the difference between a playing card (slightly rounded), a pill (very rounded), and a coin (circle).
Prompt your AI
“Make the buttons have fully rounded corners (pill shape) and the cards have slightly rounded corners”
👁️ See it in action
Shadows make elements look like they're floating above the page. They add depth and help things stand out.
A soft shadow under or around a box. Bigger shadows = element looks more 'lifted' off the page.
🧠 Analogy: Like the shadow a sticky note casts on your desk — it shows the note is on top.
Prompt your AI
“Add a subtle shadow to the cards, and make the shadow bigger when someone hovers over a card”
👁️ See it in action
Layout is how elements are arranged on the page. By default, things stack vertically. Flexbox lets you put things side by side.
Elements stack on top of each other, each taking the full width. This is the default for headings, paragraphs, and divs.
🧠 Analogy: Like stacking boxes in a column — each box takes a whole row.
Puts child elements side by side in a row (or column if you choose). The most common way to lay things out.
🧠 Analogy: Like putting books on a shelf — they sit next to each other in a row.
Prompt your AI
“Put the three feature cards side by side using flexbox with equal spacing between them”
The space between flex or grid items. Way easier than adding margins to each individual item.
🧠 Analogy: Like adjusting the dividers between folders in a filing cabinet.
Prompt your AI
“Add a 24px gap between the cards”
👁️ See it in action
Opacity controls how see-through an element is. 100% is fully visible, 0% is invisible.
Goes from 0 (invisible) to 1 (fully visible). 0.5 is 50% transparent — like frosted glass.
🧠 Analogy: Like adjusting the opacity slider on a photo in Canva.
Prompt your AI
“Make the background overlay 50% transparent so you can still see the image behind it”
👁️ See it in action
Hover effects change how something looks when you move your mouse over it. Transitions make those changes smooth instead of instant.
A different style that only shows when the mouse is over the element. Commonly used for buttons, links, and cards.
🧠 Analogy: Like a door handle that lights up when you reach for it.
Prompt your AI
“When hovering over the button, make it a darker shade of purple”
Makes changes happen gradually (over 0.2-0.3 seconds) instead of snapping instantly. Makes everything feel polished.
🧠 Analogy: The difference between a light switch (instant) and a dimmer (smooth).
Prompt your AI
“Add a smooth transition so the button color change on hover takes 0.2 seconds”
👁️ See it in action
Grid is a two-dimensional layout system — it handles rows AND columns at the same time. While Flexbox is great for arranging things in a single line, Grid shines when you need a full page layout or a card grid.
Defines how many columns your grid has and how wide each one is. 'repeat(3, 1fr)' means three equal-width columns.
🧠 Analogy: Like setting up columns in a spreadsheet — you decide how many and how wide.
Prompt your AI
“Create a 3-column grid of product cards that are evenly spaced”
Same idea but for rows. You can set specific heights or let rows auto-size based on content.
🧠 Analogy: Like setting row heights in a spreadsheet.
Prompt your AI
“Make the first row of the grid taller for a featured item and the rest auto-sized”
The space between grid items — both between columns and between rows. One property for both directions.
🧠 Analogy: Like the gutters between columns in a newspaper.
Prompt your AI
“Add a 20px gap between the grid items”
An item can stretch across multiple columns (or rows). Great for featured cards or hero sections within a grid.
🧠 Analogy: Like merging cells in a spreadsheet — one item takes up more space.
Prompt your AI
“Make the first card in the grid span two columns so it looks like a featured item”
👁️ See it in action
A 3-column grid. Item 4 stretches across two columns.
Positioning controls exactly where an element sits on the page. Most of the time you won't need it (Flexbox and Grid handle layout), but it's essential for things like sticky headers, tooltips, and overlays.
The normal flow — elements appear in the order they're written. You almost never set this explicitly.
🧠 Analogy: Like words on a page — they just go in order, one after another.
The element stays in its normal spot but you can nudge it with top/left/right/bottom. Other elements don't move.
🧠 Analogy: Like shifting a picture slightly on a wall without removing the nail hole.
Prompt your AI
“Nudge the icon 4px up from its natural position using relative positioning”
The element is removed from the normal flow and positioned relative to its nearest positioned parent. Other elements act like it doesn't exist.
🧠 Analogy: Like sticking a post-it note anywhere on a whiteboard — it floats on top.
Prompt your AI
“Position a notification badge in the top-right corner of the avatar using absolute positioning”
Stuck to the browser window — it doesn't move when you scroll. Used for sticky headers and floating buttons.
🧠 Analogy: Like a sticker on your monitor screen — always visible no matter what's behind it.
Prompt your AI
“Make the navigation bar fixed at the top of the page so it stays visible when scrolling”
A mix of relative and fixed — it scrolls normally until it reaches a point, then sticks. Perfect for table headers.
🧠 Analogy: Like a bookmark that slides along until it catches on the edge of the page.
Prompt your AI
“Make the section heading sticky so it stays at the top while scrolling through that section”
👁️ See it in action
When elements overlap, z-index decides which one shows on top. Think of your screen as having invisible layers stacked from back to front — like layers in Photoshop or Canva.
A number that sets the layer. Higher numbers sit on top of lower numbers. Default is 0 (auto).
🧠 Analogy: Like stacking playing cards — the card with the highest number goes on top of the pile.
Prompt your AI
“Make sure the dropdown menu appears on top of the other content by giving it a higher z-index”
Z-index only works on positioned elements (relative, absolute, fixed, or sticky). Without positioning, z-index is ignored.
🧠 Analogy: You can only rearrange cards if they're on the table — cards still in the box don't count.
Prompt your AI
“The modal is appearing behind the header — increase its z-index to 50 so it appears on top of everything”
👁️ See it in action
Higher z-index = closer to you. The green card (z-index 3) sits on top.
When content is bigger than its container, overflow decides what happens. Should it spill out? Be clipped? Show a scrollbar? You get to choose.
Anything that doesn't fit is clipped and invisible. Great for clean card edges or hiding extra content.
🧠 Analogy: Like a picture frame — whatever extends past the frame is hidden.
Prompt your AI
“Hide any text that overflows the card container so it looks clean”
Adds a scrollbar so users can scroll to see the rest. 'auto' only shows the scrollbar when needed, 'scroll' always shows it.
🧠 Analogy: Like a tiny window with a scroll — you peek through and scroll to see more.
Prompt your AI
“Add a scrollbar to the chat message area so users can scroll through older messages”
👁️ See it in action
This is a lot of text to demonstrate overflow behavior. When content is taller than its container, you need to decide what happens. Should it be hidden? Should it scroll? CSS gives you control over this with the overflow property. Here is even more text to make sure we overflow the container nicely.
This is a lot of text to demonstrate overflow behavior. When content is taller than its container, you need to decide what happens. Should it be hidden? Should it scroll? CSS gives you control over this with the overflow property. Here is even more text to make sure we overflow the container nicely.
Media queries let your design change based on the screen size. This is how a website can look great on a phone, tablet, and desktop — all with the same code.
Start by designing for small screens, then add rules for larger screens. This is the standard approach used by Tailwind CSS and most modern frameworks.
🧠 Analogy: Like packing a small suitcase first, then upgrading to a bigger one if needed.
Prompt your AI
“Make the layout mobile-first: single column on phones, two columns on tablets, three columns on desktop”
640px (small phones → larger phones), 768px (tablets), 1024px (laptops), 1280px (desktops). These are the screen widths where your layout changes.
🧠 Analogy: Like clothing sizes — S, M, L, XL. Each size gets a slightly different fit.
Prompt your AI
“At 768px and above, switch the layout from a single column to a two-column grid”
👁️ See it in action
CSS variables (also called custom properties) let you store a value once and reuse it everywhere. Change the variable, and every element using it updates automatically. This is how themes and design systems work.
You create a variable with a double-dash name like --primary-color. Then you use it anywhere with var(--primary-color).
🧠 Analogy: Like a nickname — instead of saying 'that specific shade of purple (#8B5CF6)' every time, you just say 'primary color'.
Prompt your AI
“Create a CSS variable called --primary-color set to purple, and use it for all buttons and links”
Change one value and it updates everywhere. Want to switch your entire color scheme? Just update the variable. No hunting through hundreds of lines.
🧠 Analogy: Like find-and-replace — but automatic and always in sync.
Prompt your AI
“Set up CSS variables for primary color, secondary color, and border radius so I can easily change the theme later”
👁️ See it in action
One variable, three elements updated at once. That's the power of CSS variables.
Transforms let you rotate, resize, and move elements without changing the layout. They're perfect for hover effects, animations, and making things feel interactive.
Spins an element by a certain number of degrees. Positive = clockwise, negative = counter-clockwise.
🧠 Analogy: Like turning a photo slightly to give it a casual, tilted look.
Prompt your AI
“Rotate the image slightly (3 degrees) to give it a playful, casual feel”
Makes an element bigger or smaller. scale(1.1) = 10% bigger. scale(0.9) = 10% smaller. Great for hover effects.
🧠 Analogy: Like pinching to zoom on your phone.
Prompt your AI
“Make the card grow slightly (scale to 1.05) when someone hovers over it”
Moves an element up, down, left, or right without affecting other elements. translateY(-4px) moves it up 4 pixels.
🧠 Analogy: Like sliding a card across a table — it moves but nothing else shifts.
Prompt your AI
“Move the button up 2px on hover to create a subtle 'lift' effect”
👁️ See it in action
Animations make elements move, fade, or change over time — automatically, without any hover or click needed. They're built with keyframes that define what happens at each stage of the animation.
A set of steps that describe the animation. You define what the element looks like at the start (0%) and end (100%), and the browser fills in the in-between.
🧠 Analogy: Like a flipbook — you draw the key frames and the pages in between create the motion.
Prompt your AI
“Create a keyframe animation that fades an element in from transparent to fully visible”
Transitions need a trigger (like hover). Animations run on their own, can repeat, and can have multiple steps. Use transitions for simple hover effects, animations for loading spinners and attention-grabbers.
🧠 Analogy: Transitions are like a light switch (on/off). Animations are like a music playlist (they keep going).
Prompt your AI
“Add a gentle pulsing animation to the notification badge so it draws attention”
👁️ See it in action
You don't need to write CSS by hand. Understanding these concepts helps you describe what you want to your AI tool more clearly — and that means better results, faster.