Create basic website layout with HTML CSS

This is going to be a short and basic tutorial meant especially for beginners. We will create a basic website layout with HTML CSS. Almost every website consists of this basic layout which includes a Header, Sidebar, Content Area, and footer.

Create basic website layout with HTML CSS

We are going to use HTML’s DIV tag because this will be a DIV based design and we are only using HTML and CSS. DIV based designs are much efficient and results in much cleaner code as compared to table based designs. In table-based designs, we use <table> tag and its columns / Rows to build the layout which is not considered a proper way at all.

Let’s get started

In the beginning, you will have the design which is either created by you or provided by another designer or client. You can see the design in the picture below.

Design - Create basic website layout with HTML CSS

Since this is only an empty demo design so, there are only four sections. Obviously, a complete website’s design will have more sections and once you learned to create this basic layout, then you will be able to create more sections easily.

HEAD section

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Demo Layout</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
</head>

In this section, we have given a page title “Demo Layout” to this page and linked a stylesheet file style.css in css directory. If you don’t know these basics you can learn more about it here.

Body section

<body>

<div class="wrap">

	<div class="header">
  	</div><!-- .header -->

	<div class="content">
	</div><!-- .content -->
    
    <div class="sidebar">
    </div><!-- .sidebar -->
	
    <div class="clear"></div>
    
	<div class="footer">
	</div><!-- .footer -->

</div><!-- .wrap -->

</body>
</html>

As you can see, we are using DIV tags and have assigned classes to each one of them. We will use these classes later in the stylesheet file by calling the names of each assigned class.
We also added comments as the same name of each assigned class after each closing DIV. Adding comments considered a good practice and this also makes the code user-friendly for other users who might be editing or reading your code.

CSS

Before styling each section, you will need to know measurements such as the width and height of each section. These measurements will obviously differ from design to design. I use the “Ruler” tool in Adobe Photoshop to get the measurements by clicking and dragging from one point to another. Measurements for this basic layout can be seen in the design picture above. You can download the attached blank PSD design as well.

.wrap {
	width:980px;
	margin:0 auto;
}

As prominent by the name “.wrap”, this is called wrapping DIV which contains all other DIVs. You can obviously assign any other name such as a wrapper, container, or main_div, etc. but I prefer to call it .wrap appears clean and short.

We have given a width of 980 pixel wide and added top/bottom margin as 0 and right /left margin as auto. That auto margin on both sides makes our website centered aligned horizontally.

body { margin:0; padding:0; }

Just resetting the default margin and padding of the body.

.header { 
	height:140px;
	margin-bottom:15px;
	background-color:#0d7963;
}

I hope this is pretty simple and explained by CSS property names that we have given it the height of 140px, bottom margin 15 pixels, and background color “#0d7963” using color code. I used the color picker tool to get color code in Adobe Photoshop.

.content {
	width:690px;
	height:450px;
	background-color:#0d7963;
	float:right;
}
.sidebar {
	width:275px;
	height:450px;
	background-color:#0d7963;
	float:left;
}

We added float property to make this DIVs floats. That way we can make these DIVs stand beside each other. Without float property, DIV would take the whole width of the page and new “.sidebar” DIV would start under “.content” DIV. You can swap the values of float to change the position of the sidebar to either on the left or right side.

.clear {
	clear:both;
}

As you noticed we used clear DIV which will probably be as it is in all other designs without any text or content in it. The purpose of this DIV is to clear the space for floating elements above otherwise footer DIV would ignore floating DIVs above and would snap to header DIV. Click here to learn more about the clear property.

.footer {
	height:70px;
	margin-top:15px;
	background-color:#0d7963;
}

Pretty simple as header DIV.

Complete HTML and CSS code

Here is the complete code for “Create basic website layout with HTML CSS”. You can also download the PSD design and HTML / CSS files from the sidebar above.

HTML

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Demo Layout</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
</head>
<body>

<div class="wrap">

	<div class="header">
  	</div><!-- .header -->

	<div class="content">
	</div><!-- .content -->
    
    <div class="sidebar">
    </div><!-- .sidebar -->
	
    <div class="clear"></div>
    
	<div class="footer">
	</div><!-- .footer -->

</div><!-- .wrap -->

</body>
</html>

CSS

body { margin:0; padding:0; }

.wrap {
	width:980px;
	margin:0 auto;
}
.header { 
	height:140px;
	margin-bottom:15px;
	background-color:#0d7963;
}
.content {
	width:690px;
	height:450px;
	background-color:#0d7963;
	float:right;
}
.sidebar {
	width:275px;
	height:450px;
	background-color:#0d7963;
	float:left;
}
.footer {
	height:70px;
	margin-top:15px;
	background-color:#0d7963;
}
.clear {
	clear:both;
}

This “Create basic website layout with HTML CSS” is a basic tutorial for beginners. You can check more HTML tutorials here. More advanced tutorials are coming soon.

哆哆女性网logo设计网站八戒美名腾起名名字测试打分番茄小说赚钱是真的吗双宝起名网站网页设计公司十堰SEO恐怖鬼故事超吓人短篇搞笑的小说苏州工业园区网站建设微信起名网免费取名大全seo技术视频教程夏邑汽车救援如何用seo技术孔孟语录读后感宣传彩页设计网站福州seo服务b2b网站的推广营销策略杨辰许若月的小说八卦周易六十四卦一字起名男孩名称《文心》读后感狸花猫作文起名网 打分网精武鸭脖官网70国支持中方涉港举措外交部回应属兔女孩子起名字移动网上营业厅查询通话记录电影新版追捕网站建设应用铁力网站优化淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻不负春光新的一天从800个哈欠开始有个姐真把千机伞做出来了国产伟哥去年销售近13亿充个话费竟沦为间接洗钱工具重庆警方辟谣“男子杀人焚尸”男子给前妻转账 现任妻子起诉要回春分繁花正当时呼北高速交通事故已致14人死亡杨洋拄拐现身医院月嫂回应掌掴婴儿是在赶虫子男孩疑遭霸凌 家长讨说法被踢出群因自嘲式简历走红的教授更新简介网友建议重庆地铁不准乘客携带菜筐清明节放假3天调休1天郑州一火锅店爆改成麻辣烫店19岁小伙救下5人后溺亡 多方发声两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#青海通报栏杆断裂小学生跌落住进ICU代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了当地回应沈阳致3死车祸车主疑毒驾武汉大学樱花即将进入盛花期张立群任西安交通大学校长为江西彩礼“减负”的“试婚人”网友洛杉矶偶遇贾玲倪萍分享减重40斤方法男孩8年未见母亲被告知被遗忘小米汽车超级工厂正式揭幕周杰伦一审败诉网易特朗普谈“凯特王妃P图照”考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼恒大被罚41.75亿到底怎么缴男子持台球杆殴打2名女店员被抓校方回应护栏损坏小学生课间坠楼外国人感慨凌晨的中国很安全火箭最近9战8胜1负王树国3次鞠躬告别西交大师生房客欠租失踪 房东直发愁萧美琴窜访捷克 外交部回应山西省委原副书记商黎光被逮捕阿根廷将发行1万与2万面值的纸币英国王室又一合照被质疑P图男子被猫抓伤后确诊“猫抓病”

哆哆女性网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化