HTML Tutorial
HTML XHTML
HTML Media
HTML Advanced
Here's a tutorial on HTML layout:
HTML (Hypertext Markup Language) provides several elements and techniques for creating layouts on a web page. The layout of a web page refers to the arrangement of content and elements on the page, such as headings, paragraphs, images, and navigation menus.
One common technique for creating layouts in HTML is to use the <div>
element. The <div>
element is a generic container element that can be used to group other elements together and apply styling with CSS (Cascading Style Sheets).
Here's an example of how to use the <div>
element to create a layout:
<div class="container"> <header> <h1>My Website</h1> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav> </header> <main> <section> <h2>Welcome to My Website</h2> <p>This is a paragraph of text.</p> </section> <section> <h2>About Me</h2> <p>Here's some information about me.</p> </section> <section> <h2>Contact Me</h2> <p>Here's how to get in touch with me.</p> </section> </main> <footer> <p>© My Website 2021</p> </footer> </div>
In this example, the <div>
element with the class "container" is used to group all of the content on the page together. Within the container, there are several other elements that are used to create the layout:
<header>
contains the website title and navigation menu<main>
contains the main content sections<footer>
contains the copyright informationEach section of the layout is contained within its own element, such as <section>
for the main content sections, and is styled using CSS to create the desired visual appearance.
In addition to the <div>
element, HTML also provides other layout elements, such as <header>
, <nav>
, <main>
, <section>
, <article>
, <aside>
, and <footer>
. These elements provide more semantic meaning to the structure of your HTML code and can help improve accessibility and search engine optimization (SEO).
By using HTML layout elements and techniques, you can create visually appealing and well-organized web pages that are easy to navigate and understand.
Creating layouts with HTML and CSS:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="styles.css"> <title>HTML Layout</title> </head> <body> <header> <h1>My Website</h1> </header> <nav> <!-- Navigation links go here --> </nav> <section> <!-- Main content goes here --> </section> <footer> <!-- Footer content goes here --> </footer> </body> </html>
HTML layout design:
<header>
, <nav>
, <section>
, <article>
, <aside>
, and <footer>
.<div id="container"> <header>Header</header> <nav>Navigation</nav> <section>Main Content</section> <aside>Sidebar</aside> <footer>Footer</footer> </div>
Responsive HTML layout:
@media (max-width: 768px) { /* Adjust styles for smaller screens */ body { font-size: 14px; } }
Grid layout in HTML:
#container { display: grid; grid-template-columns: 1fr 2fr; grid-template-rows: auto; }
Flexbox layout in HTML:
#container { display: flex; justify-content: space-between; }
HTML layout templates:
<!-- Bootstrap layout template --> <!DOCTYPE html> <html lang="en"> <head> <!-- Include Bootstrap CSS --> </head> <body> <header> <!-- Navbar goes here --> </header> <main> <!-- Main content goes here --> </main> <footer> <!-- Footer goes here --> </footer> <!-- Include Bootstrap JS --> </body> </html>
HTML layout examples:
<!-- Example: Two-column layout --> <div id="container"> <div id="sidebar">Sidebar</div> <div id="content">Main Content</div> </div>
CSS frameworks for HTML layout:
<!-- Bootstrap grid system --> <div class="container"> <div class="row"> <div class="col-md-6">Column 1</div> <div class="col-md-6">Column 2</div> </div> </div>
Fluid layout in HTML:
#container { width: 80%; margin: 0 auto; }
Fixed layout in HTML:
#container { width: 960px; margin: 0 auto; }
HTML layout structure:
<header>
, <nav>
, <main>
, <aside>
, and <footer>
.<div id="container"> <header>Header</header> <nav>Navigation</nav> <main>Main Content</main> <aside>Sidebar</aside> <footer>Footer</footer> </div>
HTML layout with divs:
<div id="header">Header</div> <div id="content">Main Content</div> <div id="footer">Footer</div>
Mobile-friendly HTML layout:
@media (max-width: 480px) { /* Mobile styles go here */ body { font-size: 14px; } }
HTML layout for SEO:
<article> <h1>SEO-friendly Content</h1> <p>Article content goes here.</p> </article>
Nested layouts in HTML:
<div class="outer-container"> <div class="inner-container"> <!-- Nested content goes here --> </div> </div>
HTML layout breakpoints:
@media (min-width: 768px) { /* Adjust styles for larger screens */ body { font-size: 16px; } }
HTML layout and accessibility:
<nav aria-label="Site navigation"> <!-- Navigation links go here --> </nav>