Ankita.eth
GithubContact
  • About Ankita
  • experience
    • TECHNOLOGIES
    • Frontend
      • Javascript
      • React
      • NextJS
      • HTML & CSS
      • UI Libraries & Frameworks
        • Tailwind CSS
        • Comprehensive Guide to UI Libraries and Frameworks
    • Backend
      • Node.js
      • Express.js
    • Database
      • Mongodb, Mongoose
      • PostgresSQl
      • MySQL
    • Packege Mangers
      • NPM-Node Packege Manager
      • Yarn
      • Yarn 2 (Berry)
      • PNPM
      • BUN
      • Commands cheatsheet
    • API Providers
      • Alchemy
      • Telegram Bot
      • CoinMarket
      • Thirdweb
      • Infura
      • Moralis
    • DevOps/Infrastructure
      • Docker
      • Kubernetes
      • CI/CD
      • Docker Swam
    • Protocols
      • ERCs & EIPs
        • ERC-20
        • ERC-721
        • ERC-1155
        • ERC-4337
        • ERC-6551
        • ERC-777
        • ERC-3643
        • EIP-7702
        • ERC-7715
        • ERC-7739
        • EIP-6780
        • EIP-5792
        • ERC-4626
        • EIP-1559
        • ERC-404
        • ERC-3643
        • ERC-223
    • Web3 Toolkits
      • Foundry
      • Hardhat
      • RemixIDE
    • Messaging/Caching
      • Kafka
      • Redis
      • Sendgrid
    • Blockchain
      • Solana
      • Ethereum
      • Polygon & Zero knowldge Proof
      • Bitcoin
      • Solidity
    • Deployment Platforms
      • AWS
      • Vercel
      • Heroku, Render
      • Domain setup
  • SDKs
    • Google Cloud SDK
    • AWS SDK
    • Firebase SDK
  • EOF EVM Object Format
  • Articles
    • Medium Articles
    • 🌐 My Work
  • 📞 Get in Touch
Powered by GitBook
On this page
  • HTML (HyperText Markup Language)
  • CSS (Cascading Style Sheets)
  • Real-Time Example: Portfolio Website

Was this helpful?

  1. experience
  2. Frontend

HTML & CSS

HTML (HyperText Markup Language)

HTML stands for HyperText Markup Language. It's the standard language for creating web pages and web applications. HTML is the backbone of web development, providing the structure. It defines the structure and content of a webpage.

HTML Structure

This basic structure forms the foundation of every HTML document.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Web Page</title>
</head>
<body>
    <h1>Welcome to My Web Page</h1>
    <p>This is a paragraph.</p>
</body>
</html>

The <!DOCTYPE html> declaration is a crucial element in HTML documents for several reasons:

  • 🎨 Ensures proper rendering by telling browsers to use standards mode

  • 📌 Declares the document as HTML5

  • 🔄 Improves cross-browser compatibility

  • ✅ Enables accurate HTML validation

  • 🔮 Future-proofs your document for upcoming web standards

While a webpage might display without it, including <!DOCTYPE html> is essential for consistent functionality and adherence to web development best practices. It's a simple line of code that significantly impacts how browsers interpret and render your HTML.

  • <!DOCTYPE html>: Declares the document type.

  • <html></html>: Represents the root of an HTML document.

  • <head></head>: Contains meta-information about the webpage, like title, links, scripts, etc.

  • <meta>:

Specifies metadata about an HTML document. Common attributes include:

charset: Specifies the character encoding for the HTML document

name: Specifies a name for the metadata

content: Specifies the value associated with the name or http-equiv attribute

viewport: Controls the page's dimensions and scaling on different devices

  • <body></body>: Contains the visible content of the webpage.

  • <h1></h1>: Defines a heading.

  • <p></p>: Defines a paragraph.

HTML Elements

HTML uses various elements to structure content. Here are some common elements:

  • Headings: <h1> to <h6>

Define HTML headings, <h1> with being the highest level and <h6> the lowest.

  • Paragraphs: <p> Defines a paragraph.

  • Links: <a> </a>Defines a hyperlink, used to link from one page to another.

  • Images: <img>Defines an image in an HTML page.

  • Lists: <ul>, <ol>, <li>

  • Divisions: <div> Defines a division or a section in an HTML document.

  • Spans: <span> Used to group inline-elements in a document.

  • Tables: <table>, <tr>, <td>

  • Forms: <form>, <input>, <label>.

  • <ul></ul>: Defines an unordered list.

  • <ol></ol>: Defines an ordered list.

  • <li></li>: Defines a list item.

HTML Attributes

Attributes provide additional information about elements:

<a href="<https://www.example.com>" target="_blank">Visit Example.com</a>
<img src="image.jpg" alt="A beautiful landscape" width="300" height="200">

HTML5 New Features

HTML5 introduced several new elements and features:

  • Semantic elements: <header>, <nav>, <article>, <section>, <aside>, <footer>

  • Multimedia elements: <video>, <audio>

  • Canvas and SVG: For graphics and animations

  • Form enhancements: New input types like date, email, range

  • Local storage: For client-side data storage

HTML Diagram

HTML Element Nesting

HTML elements can be nested inside each other, creating a hierarchical structure. This nesting is crucial for organizing content and applying styles effectively. Here's a diagram illustrating HTML element nesting:

CSS (Cascading Style Sheets)

CSS (Cascading Style Sheets) is a style sheet language used to describe the presentation and layout of HTML (and XML) documents. It allows web developers to control the appearance of web pages, including elements' colors, fonts, spacing, positioning, and more. By separating the content (HTML) from its presentation (CSS), developers can create consistent and visually appealing websites.

CSS Basic Syntax

selector {
    property: value;
}

CSS Selectors

Selectors target HTML elements to apply styles:

  • Element selector: p { }

  • Class selector: .classname { }

  • ID selector: #idname { }

  • Attribute selector: [attribute="value"] { }

  • Pseudo-class selector: a:hover { }

Common CSS Properties

Here are some frequently used CSS properties:

body {
    font-family: Arial, sans-serif;
    color: #333;
    background-color: #f0f0f0;
    margin: 0;
    padding: 20px;
}

h1 {
    font-size: 24px;
    font-weight: bold;
    text-align: center;
}

.container {
    width: 80%;
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
}

CSS Types

There are three ways to include CSS in a web page:

  • Inline CSS: Styles are applied directly to HTML elements using the style attribute.

  • Internal CSS: Styles are defined within the <head> section of an HTML document.

  • External CSS: Styles are defined in a separate .css file and linked to the HTML document.

Explanation of CSS Selectors, Properties, and Values

1. Selectors

Selectors are used to target specific HTML elements for styling. The diagram shows four types of selectors:

  • Element Selectors: Target elements by their HTML tag name (e.g., p, div, h1).

  • Class Selectors: Target elements with a specific class attribute (e.g., .classname).

  • ID Selectors: Target a unique element with a specific id attribute (e.g., #idname).

  • Attribute Selectors: Target elements based on their attributes or attribute values (e.g., [type="text"]).

2. Properties

Properties define what aspect of the selected element you want to style. The diagram highlights three categories of properties:

  • Layout Properties: Control the positioning and sizing of elements (e.g., width, height, margin, padding).

  • Typography Properties: Affect text appearance (e.g., font-size, font-family, text-align).

  • Color Properties: Set colors for elements (e.g., color, background-color).

3. Values

Values are assigned to properties to specify how the property should be applied. The diagram shows three types of values:

  • Keywords: Predefined words that represent specific styles (e.g., auto, none, inherit).

  • Units: Measurements used for size-related properties (e.g., px, em, %, rem).

  • Functions: Special CSS functions that compute values (e.g., rgb(), calc(), url()).

Together, these components form the structure of CSS rules. For example:

/* Selector */
h1 {
    /* Property: Value */
    font-size: 24px;
    color: #333;
    margin-bottom: 1em;
}

In this example, 'h1' is the selector, 'font-size', 'color', and 'margin-bottom' are properties, and '24px', '#333', and '1em' are their respective values.

Common CSS Properties with Examples

Here's a list of common CSS properties grouped by category, along with examples:

Font Properties

p {
    font-family: Arial, sans-serif;
    font-size: 16px;
    font-weight: bold;
    color: #333;
}

Text Properties

h1 {
    text-align: center;
    text-decoration: underline;
    line-height: 1.5;
}

Background Properties

body {
    background-color: #f0f0f0;
    background-image: url('background.jpg');
    background-repeat: no-repeat;
    background-size: cover;
}

Dimension Properties

.box {
    width: 300px;
    height: 200px;
    margin: 10px;
    padding: 20px;
    border: 1px solid #000;
}

Display and Positioning Properties

.container {
    display: flex;
    justify-content: space-between;
}

.absolute-box {
    position: absolute;
    top: 50px;
    left: 100px;
}

.float-left {
    float: left;
    margin-right: 10px;
}

These examples demonstrate how to use common CSS properties to style various aspects of web elements, from text and fonts to layout and positioning. Experiment with these properties to achieve the desired look for your web pages.

Real-Time Example: Portfolio Website

Let's create a simple portfolio website to demonstrate HTML and CSS skills:

HTML Structure

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Portfolio</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <header>
        <h1>John Doe</h1>
        <nav>
            <ul>
                <li><a href="#about">About</a></li>
                <li><a href="#projects">Projects</a></li>
                <li><a href="#contact">Contact</a></li>
            </ul>
        </nav>
    </header>
    <main>
        <section id="about">
            <h2>About Me</h2>
            <p>I'm a web developer passionate about creating beautiful and functional websites.</p>
        </section>
        <section id="projects">
            <h2>My Projects</h2>
            <div class="project">
                <h3>Project 1</h3>
                <p>Description of project 1.</p>
            </div>
            <div class="project">
                <h3>Project 2</h3>
                <p>Description of project 2.</p>
            </div>
        </section>
        <section id="contact">
            <h2>Contact Me</h2>
            <form>
                <label for="name">Name:</label>
                <input type="text" id="name" name="name" required>
                <label for="email">Email:</label>
                <input type="email" id="email" name="email" required>
                <label for="message">Message:</label>
                <textarea id="message" name="message" required></textarea>
                <button type="submit">Send</button>
            </form>
        </section>
    </main>
    <footer>
        <p>&copy; 2024 John Doe. All rights reserved.</p>
    </footer>
</body>
</html>

CSS Styling

/* styles.css */
body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0;
}

header {
    background-color: #333;
    color: #fff;
    text-align: center;
    padding: 1rem;
}

nav ul {
    list-style-type: none;
    padding: 0;
}

nav ul li {
    display: inline;
    margin-right: 10px;
}

nav a {
    color: #fff;
    text-decoration: none;
}

main {
    padding: 2rem;
}

.project {
    background-color: #f4f4f4;
    border: 1px solid #ddd;
    padding: 1rem;
    margin-bottom: 1rem;
}

form {
    display: grid;
    gap: 1rem;
}

footer {
    background-color: #333;
    color: #fff;
    text-align: center;
    padding: 1rem;
    position: fixed;
    bottom: 0;
    width: 100%;
}

By combining HTML and CSS, you can create visually appealing and interactive web pages.

PreviousNextJSNextUI Libraries & Frameworks

Last updated 9 months ago

Was this helpful?