Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML layout

HTML layout


Web page layout is very important for improving the appearance of a website.

Please design your web page layout carefully.


Online example

Use

Web page layout with the element
How to Use
elements to add layout.

Use

Web page layout with the element
How to Use


Website Layout

Most websites arrange their content into multiple columns (like a magazine or newspaper).

Most websites can use

elements to add layout.
or

elements to create multiple columns. CSS is used to position elements, or to create backgrounds and colorful appearances for the page.
lamp Although we can use HTML table tags to design attractive layouts, table tags are not recommended as a layout tool - tables are not layout tools.

HTML Layout - Using
Element

The div element is a block-level element used for grouping HTML elements.

The following example uses five div elements to create a multi-column layout:

Example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>

Runoob Tutorial(runoob.com)

title

 

head

<body>
<div id="container" style="width:500px">
<div id="header" style=">

background-color:#FFA500;

"

<h1 style=">

margin-bottom:0;

"

Main web page heading

h1

div

<div id="menu" style=">

background-color:#FFD700;height:200px;width:100px;float:left;

"

<

b

The menu

b

<br HTML>
<br CSS>
<br JavaScript div>
<div id="content" style=">

background-color:#EEEEEE;height:200px;width:400px;float:left;

"

Content goes here

div

<div id="footer" style=">

background-color:#FFA500;clear:both;text-align:center;

"

Copyright © runoob.com

div

div

body

html

Try it »

The HTML code above produces the following result:


HTML Layout - Using Tables

Using HTML

Most sites can use

tags are a simple way to create a layout.
or

elements to create multiple columns. CSS is used to position elements, or to create backgrounds and colorful appearances for the page.
lamp Even though HTML tables can be used to create attractive layouts, tables are designed to present tabular data - tables are not layout tools!

The following example uses a table with three rows and two columns - the first and last rows use the colspan attribute to span two columns:

Example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>

Runoob Tutorial(runoob.com)

title

 

head

<body>
<table width="500" border="0">
<tr>
<td colspan="2" style=">

background-color:#FFA500;

"

<

h1

Main web page heading

h1

td

tr

<tr>
<td style=">

background-color:#FFD700;width:100px;

"

<

b

The menu

b

<br HTML>
<br CSS>
<br JavaScript td>
<td style=">

background-color:#eeeeee;height:200px;width:400px;

"

Content goes here

td

tr

<tr>
<td colspan="2" style=">

background-color:#FFA500;text-align:center;

"

Copyright © runoob.com

td

tr

table

body

html

Try it »

The HTML code above produces the following result:


HTML Layout - Useful Tips

Tip: The biggest advantage of using CSS is that if the CSS code is stored in an external style sheet, the site becomes easier to maintain. By editing a single file, you can change the layout of all pages. To learn more about CSS, visit ourCSS Tutorial。

Tip: Since creating advanced layouts is time-consuming, using templates is a quick option. Many free website templates can be found through search engines (you can use these pre-built website layouts and optimize them).


HTML Layout Tags

tag Description
Defines a section in a document, block-level
Defines a span, used to group inline elements in a document.