Forms ยท div vs section vs article ยท How CSS connects ยท span & inline โ all with real examples you can see!
Forms are how users send data to a website โ like login, signup, contact forms.
Everything inside a form goes inside the <form> tag. It has two key attributes:
<form action="login.php" method="post"> <!-- inputs go here --> </form>
WHERE to send the data. Which page/server receives it.
get โ data shows in URL (for search)
post โ data hidden (for passwords!)
The <input> tag uses type="" to change what kind of field it shows.
<!-- TEXT โ single line --> <input type="text" placeholder="Enter name"> <!-- PASSWORD โ hides typing --> <input type="password"> <!-- EMAIL โ validates @ --> <input type="email"> <!-- NUMBER โ only numbers --> <input type="number" min="1" max="100"> <!-- CHECKBOX โ tick boxes --> <input type="checkbox"> Cricket <input type="checkbox"> Football <!-- RADIO โ pick only one --> <input type="radio" name="gender"> Male <input type="radio" name="gender"> Female <!-- SUBMIT BUTTON --> <input type="submit" value="Send">
<!-- LABEL โ names the field --> <label for="city">City:</label> <!-- DROPDOWN --> <select id="city"> <option value="che">Chennai</option> <option value="mum">Mumbai</option> <option value="del">Delhi</option> </select> <!-- TEXTAREA โ multiline --> <textarea rows="4" cols="30" placeholder="Write here..."> </textarea>
name attribute!
for attribute links the label to an input using its id. This means clicking the label text also clicks/focuses the input. It's great for usability!
These all group content โ but they mean different things to the browser and search engines.
<body><section><article><div><span>
India won the match. The team played <span>brilliantly</span> today.
Team scored 3 goals in the final match.
New phone launched today. Price: โน50,000
| Tag | Meaning | Use When... | Type |
|---|---|---|---|
<div> |
No meaning โ just a generic container box | You just need to group things for styling/layout. No special meaning needed. | Block |
<section> |
A themed section of the page | You have a group of related content with a clear topic (like "About", "Services", "Contact") | Block |
<article> |
A standalone, self-contained piece | The content could be taken out and still make sense on its own โ like a blog post, news item, comment | Block |
<header> |
Top of the page or section | Logo, navigation, site title goes here | Block |
<footer> |
Bottom of the page | Copyright, links, contact info at the bottom | Block |
<nav> |
Navigation links | Menu, links to other pages | Block |
<main> |
Main content of the page | The primary content โ only ONE per page | Block |
<aside> |
Side content | Sidebars, ads, related articles (not the main point) | Block |
<span> |
No meaning โ inline container | You need to style/target a specific word or part of text inline | Inline |
<section><article><div><span>
<body> <header> <!-- TOP of page --> <h1>My Blog</h1> <nav> <a href="/">Home</a> <a href="/about">About</a> </nav> </header> <main> <!-- MAIN content --> <section> <!-- TECH section --> <h2>Tech News</h2> <article> <!-- one standalone news item --> <h3>New iPhone Released</h3> <p>Apple launched a <span class="highlight">revolutionary</span> new phone today. </p> </article> <article> <!-- another news item --> <h3>AI Update</h3> <p>New AI model released.</p> </article> </section> <div class="ad-box"> <!-- div for layout only --> Advertisement here </div> </main> <footer> <!-- BOTTOM of page --> <p>© 2025 My Blog</p> </footer> </body>
You write CSS separately โ but you need to LINK it to HTML. Here's exactly how.
style="". Highest priority but not reusable.<style> tag in <head>. Only applies to that page..css file linked with <link>. Best for real websites.<p style="color: red; font-size: 24px; background: yellow;"> Hello World </p> <h1 style="color: blue;"> Blue Heading </h1>
Hello World
โ ๏ธ Problem: You have to repeat styles on EVERY element. Not reusable!
<head> <style> /* Write CSS rules here */ p { color: red; font-size: 20px; } .blue-text { color: blue; } #title { background: yellow; } </style> </head> <body> <p>This is red</p> <p class="blue-text">Blue</p> <h1 id="title">Yellow bg</h1> </body>
This is red
Blue
โ Better! One rule styles all matching elements. But only works for this ONE page.
You create a separate file called style.css, and link it to your HTML. One CSS file can style hundreds of HTML pages!
<head> <!-- This line CONNECTS the CSS file --> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Big Title</h1> <p class="intro">Hello!</p> </body>
/* This is style.css */ h1 { color: darkblue; font-size: 36px; text-align: center; } .intro { color: gray; font-size: 18px; margin: 20px; }
rel="stylesheet" โ tells browser "this is a CSS file"href="style.css" โ the path to your CSS file. If it's in the same folder, just write the filename. If it's in a folder: href="css/style.css"
| Method | Priority | Reusable? | Best for... |
|---|---|---|---|
Inline style="" | โญโญโญ Highest | โ No | One-off quick fixes |
Internal <style> | โญโญ Medium | Only this page | Small single-page projects |
External .css file | โญ Lowest | โ Many pages | Real websites (best practice) |
The difference between block and inline is the most important layout concept in HTML.
<!-- BLOCK โ each starts new line --> <div>I am a div</div> <div>I am another div</div> <div>I am a third div</div> <!-- INLINE โ all stay on same line --> <span>I am a span</span> <span>I am span 2</span> <span>I am span 3</span>
BLOCK โ each on its own line:
INLINE โ all on one line:
span 1 span 2 span 3<span> is an inline container with NO meaning. You use it to style or target a specific word or phrase inside text โ without breaking the line!
/* CSS */ .red { color: red; font-weight: bold; } .badge { background: gold; padding: 2px 8px; border-radius: 4px; } .big { font-size: 24px; } <!-- HTML --> <p> The price is <span class="red">โน999</span> only! </p> <p> Status: <span class="badge">NEW</span> </p> <p> Score: <span class="big">95%</span> Great! </p>
The price is โน999 only!
Status: NEW
Score: 95% Great!
โ The styled part stays IN the sentence โ the line doesn't break!
โฌ๏ธ All 4 coloured words use <span> โ they stay on the same line as the text!
Now using <div> for each word โ see how each goes to new line:
โฌ๏ธ Each div forces a new line โ you can't use this inside a sentence!
<span> when you want to style something inside a line of text without breaking the flow.<div> when you want to group a whole section or block of content.<div>Hello <div>World</div> today</div> โ div breaks the line<p>Hello <span>World</span> today</p> โ span keeps it inline