π HTML/CSS Introduction
π― Complete Definition
HTML (HyperText Markup Language) is the standard markup language for creating web pages. It structures content using elements like headings, paragraphs, links, and images. CSS (Cascading Style Sheets) describes how HTML elements are displayed on screen, paper, or in other media. Together they form the foundation of the World Wide Web.
π¬ Core Characteristics
- HTML: Markup language (not programming) β defines structure and semantics.
- CSS: Style sheet language β controls layout, colors, fonts, responsiveness.
- Separation of concerns: Content (HTML) vs presentation (CSS).
- Declarative: You describe what you want, not how to achieve it.
- Accessibility: Semantic HTML ensures content is accessible to all users.
- Browser rendering: Parsed and rendered by user agents (browsers).
- Responsive by design: CSS media queries adapt to different devices.
π Industry Usage
100% of websites use HTML and CSS. Every web developer, designer, and browser relies on these technologies. Modern frameworks (React, Vue, Angular) ultimately render HTML/CSS. CSS preprocessors (Sass, Less) extend CSS capabilities. Used in web apps, mobile apps (via webviews), emails, and even PDF generation.
π Live Preview Concept:
Hello, HTML/CSS!
This is a simple web page.
π HTML Basics
π― Complete Definition
HTML documents are built with elements (tags) that define the structure. The basic template includes <!DOCTYPE html>, <html>, <head>, and <body>. Elements have opening and closing tags, attributes provide additional info. HTML5 introduced semantic elements like <header>, <nav>, <article>, and <footer>.
ποΈ Core Structure
- <!DOCTYPE html> β declares HTML5.
- <html> β root element.
- <head> β meta-information, title, links to CSS.
- <body> β visible content.
- Attributes:
id,class,src,href,alt. - Comments:
<!-- comment -->
π Text & Semantics
π― Complete Definition
Semantic HTML uses elements that convey meaning about the content they enclose. This improves accessibility, SEO, and code readability. Text elements range from headings (<h1> to <h6>) to paragraphs (<p>), and inline semantics like <strong>, <em>, <mark>.
π€ Common Semantic Tags
- <h1>-<h6> β headings (h1 most important)
- <p> β paragraph
- <strong> β important text (bold)
- <em> β emphasized text (italic)
- <blockquote> β long quotation
- <cite> β citation
- <code> β computer code
- <mark> β highlighted text
π Links & Navigation
π― Complete Definition
Hyperlinks are what make the web "web". The <a> tag (anchor) creates links to other pages, files, or locations within the same page. Navigation is typically built with <nav> wrapping lists of links. Attributes control behavior: href (destination), target (where to open), rel (relationship).
π Link Types
- Absolute:
href="https://example.com" - Relative:
href="about.html" - Internal (anchor):
href="#section" - Email:
href="mailto:user@domain.com" - Telephone:
href="tel:+1234567890" - Download:
downloadattribute
πΌοΈ Images & Media
π― Complete Definition
Images (<img>) bring visual content. <figure> and <figcaption> associate captions. For audio and video, use <audio> and <video> with source elements. Responsive images use srcset and sizes to serve different resolutions.
πΊ Media Tags
- <img> β
src(source),alt(alternative text) - <picture> β multiple sources for art direction
- <figure> β self-contained content (diagrams, code)
- <figcaption> β caption for figure
- <video> β video player with controls
- <audio> β audio player
- <iframe> β embed another document
π Tables
π― Complete Definition
HTML tables organize data in rows and columns. Use <table> with <tr> (rows), <th> (header cells), <td> (data cells). Semantic improvements: <thead>, <tbody>, <tfoot>, and scope attribute for accessibility.
ποΈ Table Structure
- <caption> β title/description of table
- <thead> β header section
- <tbody> β main data section
- <tfoot> β footer (summaries)
- colspan / rowspan β merge cells
π Forms & Inputs
π― Complete Definition
Forms (<form>) collect user input. They contain controls like text fields, checkboxes, radio buttons, and submit buttons. Attributes define behavior: action (where to send), method (GET/POST). Modern input types (email, tel, date, range) enhance UX and validation.
π Form Elements
- <input> β many types: text, password, email, number, etc.
- <textarea> β multi-line text
- <select> β dropdown list
- <button> β clickable button
- <label> β associates text with input
- <fieldset> / <legend> β groups related inputs
π¨ CSS Basics
π― Complete Definition
CSS (Cascading Style Sheets) rule sets consist of selectors and declaration blocks. Selectors target HTML elements; declarations contain property:value pairs. CSS can be inline, internal (<style>), or external (.css file). The cascade determines which rule applies when conflicts arise.
π― Selector Types
- Element:
h1 { color: blue; } - Class:
.menu { display: flex; } - ID:
#header { background: black; } - Universal:
* { box-sizing: border-box; } - Attribute:
[type="text"] { border: 1px solid; } - Pseudo-class:
a:hover { color: red; } - Pseudo-element:
p::first-line { font-weight: bold; }
π¦ Box Model
π― Complete Definition
The CSS box model describes the rectangular boxes generated for elements. It consists of: content, padding (inside border), border, and margin (outside). Understanding the box model is essential for layout control. box-sizing: border-box; includes padding and border in width/height.
π¦ Box Components
- Content: actual text/image
- Padding: transparent space around content
- Border: line surrounding padding
- Margin: space outside border (collapsing)
- Width/Height: by default only content width
π Box Model Visual:
π² Layout & Flexbox
π― Complete Definition
Flexbox (Flexible Box Layout) is a oneβdimensional layout model for distributing space and aligning items. It excels at rows or columns. The parent (display: flex) controls flow, wrapping, alignment; children can grow, shrink, or reorder.
ποΈ Flexbox Properties
- Container:
flex-direction,flex-wrap,justify-content(main axis),align-items(cross axis),align-content - Items:
flex-grow,flex-shrink,flex-basis,align-self,order
π Flexbox Preview:
π³ CSS Grid
π― Complete Definition
CSS Grid is a twoβdimensional layout system that can handle both rows and columns simultaneously. Define a grid container with display: grid, then set track sizes with grid-template-columns/rows. Place items using line numbers, named areas, or spans.
π§© Grid Concepts
- Grid container:
display: grid - Tracks:
grid-template-columns: 1fr 2fr 1fr; - Gaps:
gap: 20px; - Lines: numbered automatically
- Areas:
grid-template-areasfor named placement - Item placement:
grid-column: span 2;
π± Responsive Design
π― Complete Definition
Responsive Web Design ensures content looks good on all devices. Core techniques: fluid grids (using % or fr), flexible images (max-width: 100%), and media queries that apply CSS based on viewport width, resolution, or orientation. Mobileβfirst approach starts with small screen styles then enhances.
π Media Query Examples
@media (max-width: 600px) { ... }@media (min-width: 768px) and (max-width: 1024px) { ... }@media (orientation: portrait) { ... }@media (prefers-color-scheme: dark) { ... }
β¨ Animations
π― Complete Definition
CSS animations bring interfaces to life. Two primary methods: transition (simple state changes) and @keyframes (complex multiβstep animations). Properties like transform (translate, rotate, scale) and opacity are performanceβoptimized (GPU accelerated).
π¬ Animation Properties
- transition:
property duration timing-function delay - transform:
translateX(20px),rotate(45deg) - @keyframes: define animation steps
- animation: name duration timing-function iteration-count
π Hover to see transition:
π Advanced CSS
π― Complete Definition
Modern CSS includes powerful features like custom properties (CSS variables), calc(), min()/max()/clamp(), nesting (native), container queries, subgrid, and :has() relational pseudo-class. Preprocessors (Sass, PostCSS) extend syntax but native CSS is catching up.
π Cuttingβedge Features
- CSS Variables:
--main-color: purple;var(--main-color) - calc():
width: calc(100% - 40px); - clamp():
font-size: clamp(1rem, 4vw, 2rem); - Container queries:
@container (min-width: 400px) { ... } - :has():
div:has(p) { border: 1px solid; }β parent selector - Nesting (native):
parent { & child { } }