CSS complete learning guide

CSS Syntax5 / 22 · Keep scrolling
Foundations & selectors

What is CSS?

Understand the concept

CSS HTML ki appearance badalta hai: colors, fonts, spacing aur layout. Pehle element select karein, phir property aur value likhein.

Keep this in mind

HTML content banata hai; CSS uska look aur layout set karta hai.

01 · Understand02 · See every example03 · Try it yourself
BUILD YOUR UNDERSTANDING

HTML gives content. CSS gives it a design.

CSS = Cascading Style Sheets. CSS browser ko batati hai ki HTML ka content kaisa dikhna chahiye—colour, font, spacing, border, background aur layout.

HTML

Structure & meaning

Heading, paragraph, image aur button banata hai.

<h2>Study Club</h2>

CSS

Appearance & layout

Un elements ka colour, size aur position set karta hai.

h2 { color: blue; }

JavaScript

Behaviour

Click par menu kholna ya content update karna.

button.addEventListener(...)

Same HTML. Try adding the CSS.

Button dabayein: content same rahega, design badlega.

index.html
YOUR FIRST WEB PAGE

Study Club

Learn one new idea every day.

HTML: the content
<section class="study-card">
  <h2>Study Club</h2>
  <p>Learn one new idea every day.</p>
  <button>Explore courses</button>
</section>
CSS: switch it on to see the result
.study-card {
  padding: 28px;
  border-radius: 18px;
  background: #eff6ff;
}
.study-card h2 { color: #2563eb; }
HTML contentCSS rulesBrowser output
Pehle element banta hai, phir CSS usse style karti hai. CSS se text ki meaning change nahi hoti; presentation change hoti hai.
QUICK CHECK

Heading ka colour badalna hai. Kaunsi technology use hogi?

Detailed explanation & examples

Compare each visual with the code directly below it.

What is CSS?

CSS (Cascading Style Sheets) is the language we use to style web pages. It's the artistic palette that brings HTML to life, controlling layout, colors, fonts, spacing, and more.

Styling

Define colors, fonts, and visual appearance of elements

Layout

Control positioning and arrangement of elements

Responsive Design

Create layouts that adapt to different screen sizes

Animations

Add dynamic effects and transitions

Try a complete example

Try this lesson
index.html
<h1 id="title">Learn CSS</h1>
<p class="highlight">Style this paragraph.</p>
<div class="demo card">A content box</div>
<ul><li>One</li><li>Two</li><li>Three</li></ul>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTEREvolution of CSS
Foundations & selectors

Evolution of CSS

Understand the concept

CSS ka development levels aur modules mein hua. Aaj alag CSS features alag specifications mein develop hote hain.

Keep this in mind

CSS3 ek single release ya ek saal ka complete package nahi hai.

01 · Understand02 · See every example03 · Try it yourself
THE STORY OF CSS

Why CSS was created—and how it grew

Web pages badhne par har heading aur paragraph ka design HTML ke andar baar-baar likhna mushkil tha. CSS ne content aur presentation ko alag rakhne ka standard tareeka diya.

THE PROBLEM

Many pages, repeated styling

20 pages ki headings ka colour badalna ho to har jagah individual style edit karni pad sakti thi.

20 pages
THE IDEA

One stylesheet, reusable rules

Pages ko ek common CSS file se link karein. Ek rule update karne par usse linked pages ka design update ho sakta hai.

styles.cssPage 1 · Page 2 · Page 3

Kisi milestone ko select karke uska meaning padhein.

1994

An idea for stylesheets

Håkon Wium Lie proposed CSS while working at CERN. Web authors needed a way to describe presentation separately from HTML content.

HTML could describe the document; a stylesheet could describe its appearance.

Modern CSS develops in modules

Ek team layout par aur doosri colour ya selectors par kaam kar sakti hai. Har module apne pace par aage badhta hai.

SelectorsColoursFlexboxGridMedia queriesCustom propertiesTransformsAnimations
History ko aise yaad rakhein: 1994 idea → 1996 CSS1 → 1998 CSS2 → modules. CSS 2.1 ka Recommendation 2011 mein aaya. Saari CSS3 features ek saath 2011 mein release nahi hui thi.

History references: W3C CSS timeline · CSS 2.1 publication history · CSS modules

QUICK CHECK

Kya saari CSS3 features ek single 2011 release ka hissa thin?

Detailed explanation & examples

Compare each visual with the code directly below it.

Evolution of CSS

1994: The Beginning

Håkon Wium Lie proposes CSS while working at CERN alongside HTML creator Tim Berners-Lee

1996: CSS1

CSS Level 1 becomes a W3C Recommendation, introducing basic styling capabilities

1998: CSS2

CSS Level 2 adds positioning, z-index, media types, and bidirectional text

Modern CSS modules

Modern CSS is developed as separate modules, including animations, flexbox and grid; they did not all arrive in one release.

Try a complete example

Try this lesson
index.html
<h1>CSS timeline</h1><ol><li>CSS1: basic styling</li><li>CSS2: positioning and more</li><li>Modern CSS: independent modules</li></ol>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERCharacteristics of CSS
Foundations & selectors

Characteristics of CSS

Understand the concept

CSS HTML ki appearance badalta hai: colors, fonts, spacing aur layout. Pehle element select karein, phir property aur value likhein.

Keep this in mind

HTML content banata hai; CSS uska look aur layout set karta hai.

01 · Understand02 · See every example03 · Try it yourself
BUILD YOUR UNDERSTANDING

One rule can improve many elements

CSS ki strength sirf decoration nahi hai. Reusable rules se consistency milti hai aur ek change ko multiple places par apply kar sakte hain.

Change one shared rule
PAGE 01

Course overview

All three headings use the same class.

class="page-title"
PAGE 02

Lesson page

All three headings use the same class.

class="page-title"
PAGE 03

Practice project

All three headings use the same class.

class="page-title"
CSS example
.page-title {
  color: #2563eb;
}

Reusable

Ek class ko multiple elements par laga sakte hain.

Consistent

Buttons, headings aur cards ka design common rehta hai.

Maintainable

Shared stylesheet mein edit karke linked pages ko update kar sakte hain.

Responsive

Screen space ke hisaab se layout adapt kar sakte hain.

Try a narrow layout

Same content ko kam space dene par cards wrap honge.

ReadTryBuild
CSS files browser mein cache ho sakti hain, jisse repeat visits par downloads kam ho sakte hain. Offline availability caching aur application setup par depend karti hai.
QUICK CHECK

Same class ko 3 pages par style karna hai. Kya common external stylesheet use kar sakte hain?

Detailed explanation & examples

Compare each visual with the code directly below it.

Characteristics of CSS

  • Time-saving: CSS allows you to apply styles to multiple HTML elements at once, saving time and effort compared to inline styles.
  • Superior to HTML: CSS provides more advanced styling options, such as layout control, typography, and animations, which are not easily achievable with HTML alone.
  • Offline browsing: CSS files can be cached by the browser, allowing for faster page loading and offline browsing.
  • Separation of concerns: CSS separates the presentation from the content, making it easier to maintain and update the website's appearance.

Try a complete example

Try this lesson
index.html
<h1>Reusable styles</h1><p class="note">First note</p><p class="note">Second note</p>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERThree Ways to Insert CSS
Foundations & selectors

Three Ways to Insert CSS

Understand the concept

Inline mein style attribute, internal mein <style>, external mein alag .css file use hoti hai. Reusable websites mein external stylesheet kaafi useful hai.

Keep this in mind

External stylesheet ka path sahi hona chahiye. Missing file se styling load nahi hogi.

01 · Understand02 · See every example03 · Try it yourself
BUILD YOUR UNDERSTANDING

Where do you write the CSS?

Teen methods same style apply kar sakte hain. Farq yeh hai ki CSS kahan rakhi hai aur usse kitne elements/pages share kar sakte hain.

Inline CSS

Opening HTML tag ke style attribute mein.

Ek element
index.html
<p style="color: blue; font-size: 20px;">
  Learning CSS
</p>
EXPECTED OUTPUT

Learning CSS

Blue text · 20px font size
style attribute mein selector aur outer braces nahi likhte. Sirf declarations hoti hain.
Common confusion

External CSS hamesha low priority aur internal CSS hamesha high priority nahi hoti. Normal internal/external rules ke beech matching, specificity aur source order matter karte hain. Selectors ke baad Priorities of CSS chapter mein cascade dekhein.

QUICK CHECK

External stylesheet link karne ke liye kaunsa element use hota hai?

Detailed explanation & examples

Compare each visual with the code directly below it.

Three Ways to Insert CSS

Inline CSS

Applied directly to HTML elements

Internal CSS

Written in the HTML file's head section

External CSS

Stored in a separate .css file

1. Inline CSS Example

Applied directly to HTML elements using the style attribute

Example
<p style="color: blue; font-size: 16px; margin: 10px;">This is styled text</p>

2. Internal CSS Example

Written in the HTML file's head section using style tags

Example
<head>
        <style>
            p {
                color: blue;
                font-size: 16px;
                margin: 10px;
            }
            .highlight {
                background-color: yellow;
            }
        </style>
    </head>

3. External CSS Example

Linked to HTML file using the link tag

Example
<head>
        <link rel="stylesheet" href="styles.css">
    </head>

Contents of styles.css:

Example
/* styles.css */
    p {
        color: blue;
        font-size: 16px;
        margin: 10px;
    }

    .highlight {
        background-color: yellow;
    }

Try a complete example

Try this lesson
index.html
<h1 style="color:purple">Inline colour</h1>
<style>p { font-weight:bold; }</style>
<p>Internal weight + external background</p>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERCSS Syntax
Foundations & selectors

CSS Syntax

Understand the concept

CSS HTML ki appearance badalta hai: colors, fonts, spacing aur layout. Pehle element select karein, phir property aur value likhein.

Keep this in mind

HTML content banata hai; CSS uska look aur layout set karta hai.

01 · Understand02 · See every example03 · Try it yourself
BUILD YOUR UNDERSTANDING

Build a valid rule, one declaration at a time

selector { property: value; } ek CSS rule ka basic format hai. Braces declarations ko group karte hain; colon property/value ko separate karta hai; semicolon declarations ko separate karta hai.

pSelectorWhich element?
{
font-sizePropertyWhat changes?
:
24pxValueWhat setting?
;}

Change the value. Watch the text.

CSS example
p {
  font-size: 24px;
  color: #2563eb;
}

Correct property name

Use font-size, with a hyphen. fontsize is a different, invalid name.

Correct value

A size such as 24px needs its unit. A colour can be a name or a valid colour value.

Separate declarations

Use a semicolon between declarations. Keeping the final semicolon makes editing easier.

CSS comments

Write /* a comment */. CSS comment syntax differs from an HTML comment.

QUICK CHECK

Valid declaration kaunsi hai?

Detailed explanation & examples

Compare each visual with the code directly below it.

CSS Syntax

The basic CSS syntax consists of three parts:

Example
Selector{ Property:Value; }

Selector

The HTML element or elements you want to style.

Example
p, h1, div {

Property

The specific style attribute you want to change.

Example
color: blue;

Value

The new value you want to apply to the property.

Example
font-size: 16px;

Complete Example

Example
p, h1, div {
color: blue;
font-size: 16px;
margin: 10px;
}

Try a complete example

Try this lesson
index.html
<p>Selector → property → value</p>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERCSS Selectors
Foundations & selectors

CSS Selectors

Understand the concept

Selector batata hai style kin elements par lagega. Element, class, ID, attribute aur combinators ko ek-ek karke practice karein.

Keep this in mind

div p sab descendant paragraphs select karta hai; div > p sirf direct children.

01 · Understand02 · See every example03 · Try it yourself
THE SELECTOR EXPLORER

Selectors: point CSS at the right elements

Selector ek condition hai: kaunse HTML elements par rule apply hoga? Neeche valid selector choose karein. Matching elements highlight honge aur count bhi badlega.

Basics

Universal selector

*

Har element ko select karta hai.

* means every element in the example document.
14 matching elements in this example
<div class="card">Selected
<h2>CSS course</h2>Selected
<p id="intro">First paragraph</p>Selected
<section>Selected
<p class="note highlight">Nested paragraph</p>Selected
</section>
</div>
<p class="note">Immediately after the div</p>Selected
<p>Another following paragraph</p>Selected
<ul>Selected
<li>HTML</li>Selected
<li>CSS</li>Selected
<li>JavaScript</li>Selected
</ul>
<input type="email" required>Selected
<input type="checkbox">Selected
<a href="https://example.com">Read more</a>Hover / focus this link
Apply this rule to the matching elements
* {
  color: #1d4ed8;
  background-color: #dbeafe;
}
,

OR / group

h2, p

Heading aur paragraphs.

space

Inside, any depth

.card p

Direct aur nested paragraphs.

>

Direct child

.card > p

Sirf ek level neeche.

+ / ~

Following siblings

.card + p

Same parent; + immediate, ~ all matching later siblings.

Dot, hash aur space ko dhyan se dekhein. .note class hai; #note ID hai. .note.highlight ek element par dono classes maangta hai; .note .highlight descendant relationship maangta hai.

:hover / :focus

Pseudo-class element ki state ya position check karti hai. Hover pointer ki state hai; focus keyboard/click selection ki state hai. Dono ko same na samjhein.

::first-letter

Pseudo-element element ke ek part ko style karta hai. Is paragraph ka first letter dekhein:

Learning CSS starts with small experiments.

Style only the first letter of a paragraph
p::first-letter {
  color: #2563eb;
  font-size: 2em;
  font-weight: bold;
}
Selectors do not edit the HTML.

Matching elements par declarations apply hoti hain. Agar selector kisi element ko match nahi karta, browser us rule ko us element par apply nahi karega. Class aur ID ke names HTML se exactly match hone chahiye.

QUICK CHECK

.card > p nested section ke andar wale paragraph ko bhi select karega?

Detailed explanation & examples

Compare each visual with the code directly below it.

CSS Selectors

1. Universal Selector (*)

Applies styles to all elements on the page.

Example
* {
margin: 0;
padding: 0;
}

2. ID Selector (#)

Targets a unique element based on its ID attribute.

Example
#my-element {
color: red;
}

3. Class Selector (.)

Targets elements based on their class attribute.

Example
.my-class {
font-size: 18px;
}

4. Attribute Selector ([attr])

Targets elements based on their attribute values.

Example
a[target="_blank"] {
color: green;
}

5. Attribute Equal Value Selector ([attr="value"])

Targets elements with a specific attribute value.

Example
input[type="text"] {
border: 1px solid #ccc;
}

4. Group Selector (element, element)

Applies the same style to multiple elements.

Example
h1, h2, h3 {

                font-weight: bold;

            }

5. Descendant Selector (element element)

Targets elements that are descendants of a specified element.

Example
div p {

                color: blue;

            }

6. Child Selector (element > element)

Targets direct children of a specified element.

Example
ul > li {

                list-style-type: square;

            }

7. Adjacent Sibling Selector (element + element)

Targets an element that is immediately preceded by another element.

Example
h1 + p {

                font-style: italic;

            }

8. General Sibling Selector (element ~ element)

Targets all siblings of an element that follow it.

Example
h1 ~ p {

                font-size: 14px;

            }

9. :nth-child() Pseudo-Class

Targets elements based on their position in a parent element.

Example
li:nth-child(2) {

                background-color: lightgray;

            }
Handwritten PDF · pages 8–9

Using more than one class

Ek element par multiple classes ho sakti hain. .card.note dono classes wale ek hi element ko select karta hai; .card .note kisi descendant ko.

class="card note"
Both classes on one element
Example
.card.note { border: 3px solid #2563eb; }
Parent .card → child .note
A descendant inside the card
Example
.card .note { background: #fef3c7; }

Try a complete example

Try this lesson
index.html
<div class="card"><p id="intro">Direct child</p><section><p>Descendant</p></section></div><ul><li>One</li><li>Two</li><li>Three</li><li>Four</li></ul><input type="text" placeholder="An attribute selector">

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERPriorities of CSS
Foundations & selectors

Priorities of CSS

Understand the concept

Same element par multiple rules lagen to cascade decide karta hai kaunsa rule apply hoga. Same origin, importance aur layer mein ID ki specificity class se zyada hoti hai.

Keep this in mind

!important selector specificity nahi hai. Origin, importance aur layers bhi matter karte hain; equal specificity mein later rule jeetta hai.

01 · Understand02 · See every example03 · Try it yourself
UNDERSTAND THE CASCADE

When several rules match, which one wins?

Ek paragraph par multiple rules match kar sakti hain. Browser har property ke liye winning declaration choose karta hai. Yahan sab rules same author origin aur same layer mein hain.

1Does it match?

Selector ko element match karna chahiye.

2Importance

Is lab mein important declarations normal declarations se upar hain.

3Specificity

Normal inline → ID → class → element.

4Source order

Baaki sab equal ho to later declaration jeetti hai.

All these selectors match this paragraph
<p id="intro" class="note">Which colour wins?</p>
Wins
YOUR PARAGRAPH

Which colour wins?

#introEnable/disable rules and try an important declaration.
Enabled declarations, in source order
p { color: #059669; }
.note { color: #2563eb; }
#intro { color: #7c3aed; }
Try this: enable the later ID rule to see source order. Then make the element rule important. Finally enable an inline style and compare normal vs important declarations.

The full cascade also accounts for origins, cascade layers, animations and transitions. This controlled example isolates importance, specificity and order so you can learn them one step at a time.

QUICK CHECK

Same origin/layer mein normal #intro aur .note dono match karte hain. Higher specificity kiski hai?

Detailed explanation & examples

Compare each visual with the code directly below it.

Priorities of CSS

Understanding CSS specificity is crucial for managing styles effectively. For rules within the same origin, importance and layer, compare specificity as shown below. Importance is a separate part of the cascade:

  1. !important Declaration

    Within the same cascade origin and layer, important declarations override normal declarations.

    Example
    p { color: blue !important; }
  2. Inline Styles

    Styles applied directly to HTML elements

    Example
    <p style="color: blue;">Text</p>
  3. ID Selectors

    Unique identifiers for elements

    Example
    #uniqueElement { color: blue; }
  4. Class, Attribute, and Pseudo-class Selectors

    Reusable styles for multiple elements

    Example
    .highlight { color: blue; }
  5. Element Selectors

    Styles applied to HTML tags

    Example
    p { color: blue; }

Try a complete example

Try this lesson
index.html
<p id="message" class="note">Which colour wins?</p>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERBorder Properties
Properties & layout

Border Properties

Understand the concept

Border element ke aas-paas ki line hai. Width, style aur color set karein; border-radius se corners round hote hain.

Keep this in mind

border: 2px solid blue mein width, style aur color teen parts hain.

01 · Understand02 · See every example03 · Try it yourself
LEARN BY SEEING

One border. Four things you control.

Interactive

Style line ka pattern hai, width uski motai, colour uska rang aur radius corners ka roundness. Kisi value ko badlein aur output dekhein.

YOUR LIVE OUTPUT
Your content
solid · 4px · 16px corners
.box {
  border: 4px solid #2563eb;
  border-radius: 16px;
}

Compare every border style

For this normal box, none and hidden show no border. They differ when resolving collapsed table borders.

Detailed explanation & examples

Compare each visual with the code directly below it.

1. Border Properties

Border properties in CSS allow you to create and style borders around HTML elements. They are essential for defining the visual boundaries and enhancing the design of web pages. Borders can be customized in terms of style, width, color, and shape.

Key aspects of border properties include:

Example
/* Border Property Syntax */
selector {
    border: width style color;
    border-radius: value;
}

(i) . Border Style Property

The border-style property specifies the type of border to display.
border-style: none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset |

dotted
Example
border-style: dotted;
dashed
Example
border-style: dashed;
solid
Example
border-style: solid;
double
Example
border-style: double;

(ii) . Border Width Property

The border-width defines the thickness of the border.

1px Width
Example
border-width: 1px;
5px Width
Example
border-width: 5px;
10px Width
Example
border-width: 10px;

(iii) . Border Color Property

The border-color sets the color of the border.

Red Border
Example
border-color: red;
Blue Border
Example
border-color: blue;
Green Border
Example
border-color: green;

(iv). Individual Border Properties

Target specific sides of the border.

Different Sides
Example
border-top: 5px dashed red;

border-bottom: 5px dotted blue;

(v). Border Shorthand

Combine width, style, and color in one declaration.

Shorthand Border
Example
border: 3px dashed orange;

(vi). Border Radius

Create rounded corners for elements.

Slight Rounding
Example
border-radius: 10px;
More Rounding
Example
border-radius: 50px;
Circular
Example
border-radius: 50%;
Handwritten PDF · pages 12–13, 26–27

Individual sides: width, style and colour

Har side ka shorthand aur longhand dono likh sakte hain. Border width px, em ya thin/medium/thick ho sakti hai; percentage valid border-width nahi hai.

LonghandMeaningValid example
border-top-widthThickness of the top edgeborder-top-width: 4px;
border-right-widthThickness of the right edgeborder-right-width: 4px;
border-bottom-widthThickness of the bottom edgeborder-bottom-width: 4px;
border-left-widthThickness of the left edgeborder-left-width: 4px;
Top side
Example
.box {
  border-top: 6px solid #2563eb;
  /* Or set the three longhands: */
  border-top-width: 6px;
  border-top-style: solid;
  border-top-color: #2563eb;
}
Right side
Example
.box {
  border-right: 6px solid #2563eb;
  /* Or set the three longhands: */
  border-right-width: 6px;
  border-right-style: solid;
  border-right-color: #2563eb;
}
Bottom side
Example
.box {
  border-bottom: 6px solid #2563eb;
  /* Or set the three longhands: */
  border-bottom-width: 6px;
  border-bottom-style: solid;
  border-bottom-color: #2563eb;
}
Left side
Example
.box {
  border-left: 6px solid #2563eb;
  /* Or set the three longhands: */
  border-left-width: 6px;
  border-left-style: solid;
  border-left-color: #2563eb;
}

Width shorthand

Example
border-width: 2px 4px 6px 8px;
/* top, right, bottom, left */

A width or colour alone does not create a visible border when border-style is none.

Try a complete example

Try this lesson
index.html
<div class="box solid">Solid</div><div class="box dashed">Dashed</div><div class="box dotted">Dotted</div>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERDisplay Property
Properties & layout

Display Property

Understand the concept

Block nayi line leta hai; inline text ke flow mein rehta hai; inline-block inline rehte hue width aur height allow karta hai.

Keep this in mind

display:none layout se bhi element hata deta hai; visibility:hidden jagah preserve karta hai.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

2. Display Property

The `display` property in CSS determines how an element is displayed in the document. It influences the layout and interaction of an element with surrounding elements. Common values are:

  • block: The element takes up the entire width of its parent, creating a new line.
  • inline: The element does not start on a new line, and its width/height cannot be manually adjusted.
  • inline-block: Similar to inline, but allows setting width and height.

Comparison of Display Properties

PropertyWidthHeightMarginPadding
blockCan be setCan be setAll sides applyAll sides apply
inlineCannot be setCannot be setHorizontal margins applyHorizontal padding applies
inline-blockCan be setCan be setAll sides applyAll sides apply

1. Display: Block

CharacteristicDescription
WidthTakes full width of parent container
Line BehaviorAlways starts on a new line
DimensionsRespects width and height properties
Example
.block-element {
    display: block;
    width: 100%;
}
Block Element 1
Block Element 2

2. Display: Inline

CharacteristicDescription
WidthOnly takes necessary content width
Line BehaviorFlows within text, no line breaks
DimensionsIgnores width and height settings
Example
.inline-element {
    display: inline;
}
Inline Element 1Inline Element 2

3. Display: Inline-Block

CharacteristicDescription
WidthConfigurable content width
Line BehaviorFlows inline with other elements
DimensionsRespects width and height properties
Example
.inline-block-element {
    display: inline-block;
    width: 150px;
}
Inline-Block 1
Inline-Block 2

Practical Use Cases

Display TypeRecommended UseExample Scenarios
BlockLayout StructuresParagraphs, Divs, Sections
InlineText-Based ElementsSpans, Links, Bold/Italic Text
Inline-BlockInteractive ComponentsButtons, Navigation Items
Handwritten PDF · pages 28

Width, height, float and clear

Width aur height size set karte hain. Float ke paas text wrap hota hai; clear se following content float ke side mein aane se roka ja sakta hai.

Fixed vs relative width

140px
75% of parent
Example
.fixed-size { width: 140px; height: 70px; }
.relative-size { width: 75%; height: auto; }

Float: text flows alongside

Image

Text wraps beside the floated image. Once the image ends, text uses the available width.

clear: both — starts below the float.

Example
.image { float: left; margin-right: 12px; }
.next-section { clear: both; }
.parent { display: flow-root; }
PropertyValuesRemember
width / heightpx, %, autoPercentage height needs a definite containing-block height in the usual case.
floatleft, right, noneUseful for wrapping text around an image.
clearleft, right, both, noneMove following content below the selected floats.

Modern page layouts usually use Flexbox or Grid; float is still useful for text wrapping.

Try a complete example

Try this lesson
index.html
<h2>Try block / inline / inline-block</h2><a href="#">Home</a> <a href="#">About</a> <a href="#">Contact</a>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERDisplay: Flex 🔧
Properties & layout

Display: Flex 🔧

Understand the concept

Parent par display:flex lagta hai. justify-content main axis aur align-items cross axis par items align karte hain.

Keep this in mind

Main axis flex-direction se badalta hai; justify-content hamesha horizontal nahi hota.

01 · Understand02 · See every example03 · Try it yourself
LEARN BY SEEING

Arrange items, then change the axis

Interactive

Flex parent ke andar items arrange hote hain. justify-content main axis par aur align-items cross axis par kaam karta hai. Direction badalne se axes bhi badalte hain.

Main axis: horizontalCross axis: vertical
1
2
3
.parent {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

Detailed explanation & examples

Compare each visual with the code directly below it.

4. Display: Flex 🔧

What It Does: It creates a flexible layout system for arranging items in a container.
Why It’s Useful: It helps align and distribute items easily, even when their sizes vary.

Flex Item 1
Flex Item 2
Flex Item 3
Example
.flex-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
PropertyDescriptionCommon Values
display: flexCreates a flex containerflex, inline-flex
justify-contentAligns items along the main axis (set by flex-direction)center, space-between, space-around
align-itemsAligns items along the cross axiscenter, stretch, flex-start
Handwritten PDF · pages 16–19, 33–42

Put the notebook layouts into practice

Notebook ke navigation, login-card aur image-gallery layouts mein yehi display, alignment, spacing, colour aur font properties ek saath use hoti hain. Code ko HTML compiler mein copy karke change karein.

1. Navigation bar and page sections

Study StudioHome · Courses · Contact
Example
<style>
.site-header { display:flex; justify-content:space-between; align-items:center;
  gap:16px; padding:20px; background:#1e3a8a; color:white; }
.site-header nav { display:flex; gap:16px; }
.site-header a { color:white; text-decoration:none; }
.page-panels { display:flex; flex-wrap:wrap; gap:20px; padding:20px; }
.page-panels section { flex:1 1 220px; border:2px solid #cbd5e1; padding:20px; }
</style>
<header class="site-header"><strong>Study Studio</strong><nav>
  <a href="#courses">Courses</a><a href="#updates">Updates</a>
</nav></header>
<main class="page-panels"><section id="courses"><h2>Courses</h2><ul><li>HTML</li><li>CSS</li></ul></section>
  <section id="updates"><h2>Updates</h2><p>Your learning news.</p></section></main>

2. A styled form card

Course enquiry
Your name
Your email
Send enquiry
Example
<style>
.enquiry { max-width:320px; margin:30px auto; padding:24px;
  background:#f8fafc; border:1px solid #cbd5e1; border-radius:14px; font-family:Arial; }
.enquiry label { display:block; margin-top:12px; }
.enquiry input { box-sizing:border-box; width:100%; padding:10px; margin-top:5px;
  border:1px solid #94a3b8; border-radius:6px; }
.enquiry button { width:100%; margin-top:16px; padding:12px; border:0;
  border-radius:7px; color:white; background:linear-gradient(90deg,#2563eb,#7c3aed); }
</style>
<form class="enquiry" onsubmit="event.preventDefault()">
  <h2>Course enquiry</h2><label>Name<input name="name" required></label>
  <label>Email<input name="email" type="email" required></label>
  <button type="submit">Send enquiry</button>
</form>

This is a local styling demonstration. It does not create accounts or send form data.

3. Image gallery with a hover effect

Mountain landscape for the galleryMountain view
Study workspace for the galleryStudy space
Example
<style>
.gallery { display:flex; flex-wrap:wrap; justify-content:center; gap:20px; }
.gallery figure { width:220px; margin:0; border:1px solid #cbd5e1;
  border-radius:12px; overflow:hidden; background:white; }
.gallery img { width:100%; height:160px; object-fit:cover; transition:transform .3s; }
.gallery figure:hover img { transform:scale(1.05); }
.gallery figcaption { padding:14px; text-align:center; font-weight:700; }
</style>
<div class="gallery">
  <figure><img src="/practice-media/landscape.svg" alt="Mountain landscape"><figcaption>Mountain view</figcaption></figure>
  <figure><img src="/practice-media/study.svg" alt="Study workspace"><figcaption>Study space</figcaption></figure>
</div>

The final notebook pages (43–45) discuss HTML required and pattern validation. Continue with HTML Form Validation in Elements, Tags and Attributes for those HTML topics.

Try a complete example

Try this lesson
index.html
<div class="row"><div>One</div><div>Two</div><div>Three</div></div>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERCSS Box Model: Comprehensive Guide
Properties & layout

CSS Box Model: Comprehensive Guide

Understand the concept

Har box content, padding, border aur margin se milkar banta hai. Padding andar aur margin bahar ki spacing hai.

Keep this in mind

content-box mein width ke alawa padding aur border add hote hain.

01 · Understand02 · See every example03 · Try it yourself
LEARN BY SEEING

See the four layers of a CSS box

Interactive

Content sabse andar hai. Padding content ke andar ki spacing, border uski boundary aur margin doosre elements se bahar ka gap hai.

Rendered box width212px160 + 20 × 2 + 6 × 2Margin adds 48px of horizontal space outside this width.
MarginBorderPaddingContent
.box {
  width: 160px; /* content-box */
  padding: 20px;
  border: 6px solid #8b5cf6;
  margin: 24px;
}

With box-sizing: border-box, the declared width includes content, padding and border. Margin stays outside.

Detailed explanation & examples

Compare each visual with the code directly below it.

3. CSS Box Model: Comprehensive Guide

Margin
Border
Padding
Content Area
Example
/* Box Model CSS Example */
.element {
    width: 300px;          /* Content width */
    padding: 20px;         /* Internal spacing */
    border: 10px solid;    /* Element border */
    margin: 15px;          /* External spacing */
}
Handwritten PDF · pages 24–26

Margin and padding: every side

Top, right, bottom aur left ko alag set kar sakte hain. Padding element ke background ke andar hoti hai. Margin doosre elements se distance banata hai.

PropertyWhat changes?Example
margin-topSpace outside this side of the bordermargin-top: 8px;
margin-rightSpace outside this side of the bordermargin-right: 16px;
margin-bottomSpace outside this side of the bordermargin-bottom: 24px;
margin-leftSpace outside this side of the bordermargin-left: 32px;
padding-topSpace between this side and the contentpadding-top: 8px;
padding-rightSpace between this side and the contentpadding-right: 16px;
padding-bottomSpace between this side and the contentpadding-bottom: 24px;
padding-leftSpace between this side and the contentpadding-left: 32px;

Read shorthand clockwise

Four values ka order: top → right → bottom → left. Two values: top/bottom, phir left/right.

Example
.box {
  margin: 8px 16px 24px 32px;
  padding: 10px 20px;
}
/* margin: 12px;       all four sides */
/* margin: 8px 16px;   vertical, horizontal */
/* margin: 8px 16px 24px; top, horizontal, bottom */

Negative margin allowed ho sakta hai; negative padding invalid hai. Vertical margins of normal block elements can collapse. Flex/grid items behave differently.

Try a complete example

Try this lesson
index.html
<div class="box">Content</div><p>Inspect content + padding + border + margin.</p>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERBox Shadow 🌓
Properties & layout

Box Shadow 🌓

Understand the concept

box-shadow element ke bahar ya andar shadow banata hai. Offset, blur, spread aur color ko alag-alag samjhein.

Keep this in mind

Shadow layout space ko increase nahi karta.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

1. Box Shadow 🌓

What It Does: It adds a shadow to an element, making it look like it's lifted off the page.
Why It’s Useful: It gives depth and a polished look to elements.

Example
.element {
    box-shadow: 5px 5px 15px rgba(0,0,0,0.3);
}
PropertyDescriptionValue Components
box-shadowAdds shadow effect to elementx-offset, y-offset, blur-radius, color
Horizontal OffsetShadow position on X-axisPositive/Negative pixels
Vertical OffsetShadow position on Y-axisPositive/Negative pixels
Handwritten PDF · pages 33, 41–42

Hover and transition: see what changes

Hover par element ki style change hoti hai. Transition property aur duration batati hai ki change kitni smoothly hoga. Keyboard users ke liye focus-visible bhi dein.

Hover or focus this card
Example
.card {
  background: #dbeafe;
  transition: background-color .3s, transform .3s;
}
.card:hover, .card:focus-visible {
  background: #bfdbfe;
  transform: translateY(-4px);
}
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
}

transition-duration measures time (s or ms); it is not a size. Transition only the properties you intend to animate.

Try a complete example

Try this lesson
index.html
<div class="card">Hover over this card</div>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERBox Sizing 📦
Properties & layout

Box Sizing 📦

Understand the concept

box-sizing:border-box mein declared width ke andar padding aur border count hote hain.

Keep this in mind

Margin border-box width ka hissa nahi hai.

01 · Understand02 · See every example03 · Try it yourself
LEARN BY SEEING

See the four layers of a CSS box

Interactive

Content sabse andar hai. Padding content ke andar ki spacing, border uski boundary aur margin doosre elements se bahar ka gap hai.

Rendered box width212px160 + 20 × 2 + 6 × 2Margin adds 48px of horizontal space outside this width.
MarginBorderPaddingContent
.box {
  width: 160px; /* content-box */
  padding: 20px;
  border: 6px solid #8b5cf6;
  margin: 24px;
}

With box-sizing: border-box, the declared width includes content, padding and border. Margin stays outside.

Detailed explanation & examples

Compare each visual with the code directly below it.

2. Box Sizing 📦

What It Does: It decides how the size of an element is calculated (whether padding and border are included or excluded).
Why It’s Useful: It simplifies layout and ensures consistent element sizes.

Box Sizing: Border Box
Example
.element {
    box-sizing: border-box;
    width: 300px;
    padding: 20px;
    border: 10px solid red;
}
ValueDescriptionCalculation Method
content-boxDefault browser behaviorWidth = content width
border-boxIncludes padding and border in total widthWidth = content + padding + border

Try a complete example

Try this lesson
index.html
<div class="box content">content-box</div><div class="box border">border-box</div>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERBox Decoration Break 🎨
Properties & layout

Box Decoration Break 🎨

Understand the concept

box-decoration-break batata hai line ya column mein tootne wale box ka background aur border kaise paint hoga.

Keep this in mind

clone aur slice ko wrapping inline text ke saath compare karein.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

3. Box Decoration Break 🎨

What It Does: Controls how decorations like borders, backgrounds, and shadows behave when content breaks into multiple lines or boxes.
Why It’s Useful: Ensures a smooth or continuous look for elements split across lines.

Example
.element {
    -webkit-box-decoration-break: clone;
}
ValueDescriptionUse Case
sliceDefault behaviorBreaks background at element boundaries
cloneRepeats decoration across linesMulti-line text with consistent styling

Try a complete example

Try this lesson
index.html
<div style="width:230px;font-size:28px;line-height:1.8"><span class="mark">A highlighted sentence wrapping across multiple lines.</span></div>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERList Styles
Properties & layout

List Styles

Understand the concept

list-style-type marker ka design, position uski placement aur image custom marker set karti hai.

Keep this in mind

list-style shorthand mein type, position aur image combine ho sakte hain.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

4. List Styles

Defines the appearance of list markers. Can change bullets to different shapes or numbers to various numbering systems.

1. List-Style-Type

Unordered List Types

disc (Default)

  • Standard bullet point
  • Solid circular marker

circle

  • Hollow circular marker
  • Open circle style

square

  • Solid square marker
  • Block-style bullet

none

  • No visible marker
  • Clean, minimalist look
Example
/* Unordered List Type Styles */
ul { 
    list-style-type: disc;     /* Default */
    list-style-type: circle;   /* Hollow circles */
    list-style-type: square;   /* Solid squares */
    list-style-type: none;     /* No markers */
}

Ordered List Types

decimal (Default)

  1. Standard numbering
  2. 1, 2, 3, 4...

decimal-leading-zero

  1. Includes leading zero
  2. 01, 02, 03...

lower-alpha

  1. Lowercase letters
  2. a, b, c, d...

upper-alpha

  1. Uppercase letters
  2. A, B, C, D...

lower-roman

  1. Lowercase Roman
  2. i, ii, iii, iv...

upper-roman

  1. Uppercase Roman
  2. I, II, III, IV...
Example
/* Ordered List Type Styles */
ol { 
    list-style-type: decimal;               /* 1, 2, 3 */
    list-style-type: decimal-leading-zero;  /* 01, 02, 03 */
    list-style-type: lower-alpha;           /* a, b, c */
    list-style-type: upper-alpha;           /* A, B, C */
    list-style-type: lower-roman;           /* i, ii, iii */
    list-style-type: upper-roman;           /* I, II, III */
}

2. List-Style-Position

  • Outside Position (Default)
  • Markers aligned to left
  • Inside Position
  • Markers inside list content
Example
/* List Style Position */
ul { list-style-position: inside; }

Controls whether list markers are inside or outside the list item's content box.

3. List-Style-Image

Example
/* Custom Image Marker */
ul {
    list-style-image: url('/style-course/marker.svg');
}

Replaces standard markers with a custom image. Useful for unique or branded list styles.

4. List-Style (Shorthand)

Example
/* Shorthand Syntax */
ul {
    list-style: square inside url('/style-course/marker.svg');
    /* Combines type, position, and image */
}

Combines list-style-type, list-style-position, and list-style-image in a single declaration.

Try a complete example

Try this lesson
index.html
<ul><li>HTML</li><li>CSS</li></ul><ol><li>Read</li><li>Practise</li></ol>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERText Properties
Properties & layout

Text Properties

Understand the concept

Text alignment, decoration, case, spacing aur line-height readability ko control karte hain.

Keep this in mind

line-height lines ke beech aur letter-spacing letters ke beech spacing hai.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

Text Properties

Text Properties Overview

PropertyValuesExample
text-alignleft, right, center, justify
Centered Text
text-indentpixels, ems, percentage
Indented first line by 30 pixels
line-heightnormal, number, pixels, percentage
Double line height
Increased spacing between lines
letter-spacingnormal, pixels
Increased space between characters
text-decorationnone, underline, overline, line-through
Underlined Text
Example
/* Text Property Examples */
.text-styles {
    text-align: center;
    text-indent: 30px;
    line-height: 1.5;
    letter-spacing: 1px;
    text-decoration: underline;
}

Text Decoration Variations

Underline | Overline | Line Through
Example
/* Text Decoration Combinations */
.text-decoration-demo {
    text-decoration: underline wavy red;  /* Wavy underline in red */
}
Handwritten PDF · pages 20, 22–23

Vertical alignment and text colour

vertical-align inline elements aur table cells ke liye hai. Flex items ko align karne ke liye align-items use karein.

Text example

Example
vertical-align: baseline;

Text example

Example
vertical-align: super;

Text example

Example
vertical-align: sub;

Text example

Example
vertical-align: middle;

color: #2563eb changes the text colour.

Example
p {
  color: #2563eb;
  word-spacing: 4px;
  letter-spacing: 1px;
  line-height: 1.8;
}
.label { vertical-align: middle; }

text-decoration: blink is obsolete and unreliable. Use underline, overline, line-through or none in modern examples.

Handwritten PDF · pages 23

Text transform: change the displayed case

text-transform display ko badalta hai; HTML mein likha original text change nahi hota.

Learning CSS is creative

Example
text-transform: none;

Learning CSS is creative

Example
text-transform: uppercase;

Learning CSS is creative

Example
text-transform: lowercase;

Learning CSS is creative

Example
text-transform: capitalize;

Try a complete example

Try this lesson
index.html
<h1>Readable typography</h1><p>Line height controls the distance between text lines. Try changing alignment and spacing to see how the paragraph feels.</p>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERFont Properties
Properties & layout

Font Properties

Understand the concept

Font family, size, weight aur style text ka appearance set karte hain. Hamesha fallback font family rakhein.

Keep this in mind

font shorthand mein size aur family required hote hain.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

Font Properties

PropertyValuesExample
font-family - Generic families: serif, sans-serif, monospace
- Specific fonts: Arial, Times New Roman, Helvetica
- Web fonts: Google Fonts, Custom Fonts
- System fonts: system-ui
Times New Roman Text
Arial Text
Monospace Text
font-style - normal
- italic
- oblique
Normal text
Italic text
Oblique text
font-weight - normal (400)
- bold (700)
- lighter
- bolder
- 100 to 900
Normal weight (400)
Bold weight (700)
Heavy weight (900)
font-size - Absolute: px, pt
- Relative: em, rem, %
- Keywords: small, medium, large
- Viewport: vw, vh
12px text size
1.5em text size
Large text size
text-decoration - none
- underline
- overline
- line-through
- Can combine with style and color
No decoration
Underlined text
Strikethrough text
Fancy decoration

Combined Example:

This text combines multiple font properties
Handwritten PDF · pages 19–20

Font variant, font size and the font shorthand

font-variant: small-caps se small capital letters milte hain. font-weight thickness badalta hai; font-size text ka size badalta hai. Notes mein in dono ke examples ko mix na karein.

Learning CSS
Example
font-variant: normal;
Learning CSS
Example
font-variant: small-caps;
PropertyWhat changes?Example
font-sizeSize of the textfont-size: 24px;
font-weightThickness of the strokesfont-weight: 700;
font-variantSmall-cap presentationfont-variant: small-caps;

Combine font settings

Example
.intro {
  font: italic small-caps 700 20px/1.6 Georgia, serif;
}
/* style, variant, weight, size/line-height, family */

Font size and family are required in the font shorthand. Keep fallback families at the end.

Try a complete example

Try this lesson
index.html
<h1>Heading</h1><p class="intro">A short introduction.</p><p>Regular body text.</p>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERBackground Properties
Properties & layout

Background Properties

Understand the concept

Background color aur image element ke peeche dikhte hain. Repeat, size, position aur attachment ko alag test karein.

Keep this in mind

cover image ko crop kar sakta hai; contain poori image fit karta hai.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

Background Properties

Background Demonstrations

Background Color
Background Image
Background Position

Background Properties Table

PropertyValuesExample
background-colorcolor name, hex, rgb, rgba
Example
background-color: blue;
background-color: #3498db;
background-color: rgb(52, 152, 219);
background-imageurl(), linear-gradient(), radial-gradient()
Example
background-image: url('/practice-media/landscape.svg');
background-image: linear-gradient(to right, red, blue);
background-positiontop, bottom, left, right, center, px, %
Example
background-position: center;
background-position: 25% 75%;
background-position: 50px 100px;
background-sizecover, contain, px, %
Example
background-size: cover;
background-size: contain;
background-size: 200px 150px;
background-size: 50% 100%;

Shorthand Background Property

Example
/* Background Shorthand */
background: 
    #ff6b6b               /* color */
    url('/practice-media/landscape.svg')      /* image */
    no-repeat             /* repeat */
    center center         /* position */
    / cover;              /* size */
Handwritten PDF · pages 20–21, 35

Colour formats and gradients

Named colours, hex aur rgb() ek hi colour ko likhne ke alag formats hain. linear-gradient() background-image banata hai; yeh font colour ki value nahi hai.

royalblue
Example
background-color: royalblue;
#4169e1
Example
background-color: #4169e1;
rgb(65, 105, 225)
Example
background-color: rgb(65, 105, 225);
Gradient
Example
background: linear-gradient(90deg, #2563eb, #7c3aed);
Handwritten PDF · pages 21

Background repeat and attachment

Repeat image ke pattern ko control karta hai. Attachment decide karta hai ki scrolling par background image kis reference ke saath rahegi.

Example
background-repeat: repeat;
Example
background-repeat: repeat-x;
Example
background-repeat: repeat-y;
Example
background-repeat: no-repeat;
background-attachmentWhat happens when you scroll?
scrollBackground stays attached to the element; it scrolls with the page.
fixedBackground is fixed relative to the viewport in the usual case.
localBackground scrolls with the element's own content.
Example
.panel {
  background-image: url("/practice-media/landscape.svg");
  background-repeat: no-repeat;
  background-attachment: scroll;
  background-position: center;
  background-size: cover;
}

Try a complete example

Try this lesson
index.html
<div class="hero"><h1>A mountain journey</h1></div>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERCSS Position Properties
Properties & layout

CSS Position Properties

Understand the concept

Static, relative, absolute, fixed aur sticky se positioning badalti hai. Absolute element aam taur par nearest positioned ancestor ke relative hota hai.

Keep this in mind

Sticky ko inset, jaise top:0, aur suitable scroll space chahiye.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

CSS Position Properties

Position Property Overview

The CSS position property defines how an element is positioned in a document. It can change an element's layout behavior and its relationship to other elements.

Position Demonstration

Static
Relative
Absolute
Sticky
Fixed

Position Properties Table

Property ValueDescriptionExample
staticDefault positioning. Element follows normal document flow.
Example
position: static;
/* Default behavior, no special positioning */
relativePositioned relative to its normal position. Doesn't affect other elements.
Example
position: relative;
top: 20px;    /* Moves 20px down */
left: 30px;   /* Moves 30px right */
absoluteRemoved from normal document flow. Positioned relative to nearest positioned ancestor.
Example
position: absolute;
top: 50px;
right: 100px;
fixedPositioned relative to the browser window. Stays in the same place during scrolling.
Example
position: fixed;
bottom: 20px;
right: 20px;  /* Stays in bottom-right corner */
stickyStays in normal flow, then sticks to an inset within its scrolling container and containing block.
Example
position: sticky;
top: 0;  /* Sticks to top when scrolled */

Positioning Context

The positioning of elements depends on their context:

  • Static and relative positioned elements remain within the normal document flow.
  • Absolute positioned elements are taken out of the flow and positioned relative to their nearest positioned ancestor.
  • Fixed elements usually use the viewport; a transformed ancestor can create their containing block. Sticky uses its nearest scrolling ancestor and stays within its containing block.

Try a complete example

Try this lesson
index.html
<div class="card"><span class="badge">Featured</span><h2>Positioning</h2><p>The card is relative; the badge is absolute.</p></div>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERCSS Table Properties
Properties & layout

CSS Table Properties

Understand the concept

Table border, collapse, cell spacing, padding aur alignment ko set karein. Hover aur striped rows reading ko easy banate hain.

Keep this in mind

border-spacing separate borders mein kaam karta hai; collapsed borders mein nahi.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

CSS Table Properties

Table Properties Overview

CSS provides powerful properties to style and control HTML tables, allowing for more dynamic and visually appealing table designs.

Table Properties Breakdown

PropertyDescriptionExample
borderControls table and cell border appearance
Example
table {
    border: 2px solid #333;
}
td {
    border: 1px solid #ddd;
}
border-collapseDefines how table borders are rendered
Example
/* Combines adjacent cell borders */
table {
    border-collapse: collapse;
    /* or */
    border-collapse: separate;
}
width & heightSet table and cell dimensions
Example
table { 
    width: 100%; 
    height: 400px; 
}
td {
    width: 50%;
    height: 50px;
}
text-alignHorizontal alignment of cell content
Example
td {
    text-align: left; /* left, center, right */
}
vertical-alignVertical alignment of cell content
Example
td {
    vertical-align: middle; /* top, middle, bottom */
}

Table Style Demonstrations

Hoverable Table

NameRole
AliceDeveloper
BobDesigner
CharlieManager

Striped Table

ProductPrice
Laptop$999
Smartphone$599
Tablet$399
Headphones$199

Detailed Explanations

1. Table Border

Table borders define the visual boundaries of tables and cells. You can control:

  • Border width: Thickness of the border
  • Border style: solid, dashed, dotted, etc.
  • Border color: Color of the border

2. Border Collapse

This property determines how table borders are rendered:

  • collapse: Combines adjacent cell borders into a single border
  • separate: Keeps cell borders distinct with spacing

3. Table Width and Height

Control table and cell dimensions using percentage or pixel values:

  • Table width can be set to fixed or responsive percentages
  • Individual cell heights and widths can be customized

4. Horizontal and Vertical Alignment

Positioning content within table cells:

  • text-align: Aligns content horizontally (left, center, right)
  • vertical-align: Aligns content vertically (top, middle, bottom)

5. Hoverable Tables

Add interactivity by changing background on hover using :hover pseudo-class

6. Striped Tables

Improve readability by adding alternating background colors using :nth-child() selector

Try a complete example

Try this lesson
index.html
<table><thead><tr><th>Topic</th><th>Status</th></tr></thead><tbody><tr><td>Selectors</td><td>Ready</td></tr><tr><td>Layout</td><td>Practising</td></tr><tr><td>Project</td><td>Next</td></tr></tbody></table>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERCSS Grid
More practice

CSS Grid

Understand the concept

Grid rows aur columns mein layout banata hai. repeat(3,1fr) teen equal columns banata hai.

Keep this in mind

Small changes karke output compare karein. Narrow screen par bhi layout test karein.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

Example
<div class="grid"><div>One</div><div>Two</div><div>Three</div></div>
Example
.grid { display:grid; grid-template-columns:repeat(3,1fr); gap:20px; }
.grid > div { background:#dbeafe; padding:24px; }

Try a complete example

Try this lesson
index.html
<div class="grid"><div>One</div><div>Two</div><div>Three</div></div>

Open the compiler to change the code and experiment with the result.

KEEP SCROLLING · NEXT CHAPTERResponsive Design
More practice

Responsive Design

Understand the concept

Media queries se screen size ke hisaab se CSS change hoti hai.

Keep this in mind

Small changes karke output compare karein. Narrow screen par bhi layout test karein.

01 · Understand02 · See every example03 · Try it yourself

Detailed explanation & examples

Compare each visual with the code directly below it.

Example
<div class="grid"><div>One</div><div>Two</div><div>Three</div></div>
Example
.grid { display:grid; grid-template-columns:repeat(3,1fr); gap:16px; }
.grid > div { background:#dbeafe; padding:24px; }
@media (max-width:768px) { .grid { grid-template-columns:1fr; } .sidebar { display:none; } }

Try a complete example

Try this lesson
index.html
<div class="grid"><div>One</div><div>Two</div><div>Three</div></div>

Open the compiler to change the code and experiment with the result.

You have reached the end of the guide.

Revise a chapter using the sidebar, or put your skills into practice.

Explore practice projects
Hi! 👋
KnoblyAI
Online

Hello! 👋

Your futuristic AI learning companion

KnoblyAI can make mistakes. Double-check important replies.