HTML CSS Handbook Learn HTML and CSS
HTML CSS Handbook Learn HTML and CSS
First edition
Foreword
1. HTML Introduction
2. First Look
3. HTML Tags
4. Page Layout
5. Forms, Lists & Table
6. SEO
7. CSS Introduction
8. Getting Started
9. Colors & Backgrounds
10. CSS Box Model
11. Fonts & Display
12. Size & Positions
13. Flexbox
14. Grid & Media Query
15. Transforms, Transitions & Animations
16. Projects
Also by Vikalp Kaushik
Foreword
Hi there!
This book does not try to cover everything under the sun related to HTML &
CSS. It focuses on the core concepts of the HTML & CSS, trying to simplify the
more complex things.
I wish to assist you in becoming familiar with HTML & CSS and gaining a rapid
understanding of how to use this fantastic tool for creating amazing web
designs.
Vikalp Kaushik
1
HTML Introduction
HTML is the language of the web. It’s used to make web pages and pages on the
internet. HTML tags are used to define the look and feel of a website.
We can simply construct stunning websites if we learn these HTML tags and
how to put them together!
So, what’s the big deal about CSS and Java Script?
HTML is used to define a page’s layout - its bare bones structure.
Java Script is used to perform page layout logic, such as what occurs when a
user hovers over a text, when to hide or show items, and so on.
A Lovely Comparison
https://www.pinterest.ca/pin/571183165342554995/?autologin=true
Even Notepad may be used to create HTML. Alternatively, you can use any text
editor of your choosing to make these work easier.
2
First Look
Quick Points:
The HTML tag has two children: the head and body tags.
The majority of HTML components have an opening and closing tag, with
content in between.
There is no content in some HTML tags. Empty tags, such as <br>, <hr>,
and so on, are known as empty tags.
The extension .htm or .html can be used.
To inspect a website’s HTML code, utilize Chrome’s “Inspect Element” or
“View Page Source” options.
Comments in HTML
In HTML, comments are used to indicate text that should not be parsed. They
can assist in the documentation of the source code.
Case Sensitivity
HTML is a language that doesn’t care about case. The <H1> and <h1> tags are
interchangeable or same.
What to do now?
Examine your favorite website and make a change to the displayed page, or
view the page source and copy the exact lines of code.
3
HTML Tags
The page layout can be defined by adding components to the body tag.
HTML Element
From the first to the last tag, everything is included.
HTML Attributes
To add further information to an HTML tag, we use this, like href. Example:
Paragraph Tag
To add paragraphs to an HTML page, we use paragraph tags.
Anchor Tag
The Anchor tag is used to create links inside an HTML page to existing content.
Image Tag
The img tag is used to include images in an HTML document.
<br> tag
In an HTML document, the br tag is used to create line breaks.
<hr> tag
In HTML, the hr tag is used to generate a horizontal ruler that is frequently
used to separate text.
<pre> tag
Extra spaces and newlines are always ignored by HTML. We utilise pre tag to
display a piece of text in its entirety.
<pre>
This is written
using pre
tag
</pre>
What to do now?
Create a HTML page using all tags mentioned above.
4
Page Layout
<body>
<header> Navigation </header>
<main> Website content </main>
<footer> Links & Social accounts </footer>
</body>
What to do now?
Create a HTML page which opens an page when clicked on an image or link.
5
HTML forms
The form tag is used to collect input from the user using an HTML form.
<form>
-- Element of the form --
</form>
There are various form elements for various types of user input.
Input element : Text, checkbox, radio, button, and submit are examples of
input elements. There is also a file type.
Textarea element : The cols and rows attributes can be used to size the
textarea element, which defines a multi-line text input.
Select element : A drop-down list is defined by the select element.
Lists
Lists are used to display content which represents a list.
<ul>
<li> Home </li>
<li> About </li>
</ul>
Tables
In HTML, the table tag is used to define tables. It’s a tool for formatting and
displaying tabular data.
<tr> tag: Used to display table row.
<td> tag: Used to display table data.
<th> tag: Used in place of table data for displaying table headers.
To add a caption to the table, we use <caption> tag inside table.
thead tag: Used to wrap table head (caption & <tr> with <th>)
tbody tag: Used to wrap the table body.
Colspan attribute
This property is used to make cells that span multiple columns.
What to do now?
1. Create an sign up form.
2. Create a table displaying details of students.
3. Create an order list of months.
6
SEO
Types of SEO:
Onpage SEO
Offpage SEO
HTML SEO
The following strategies can be used by HTML developers to create SEO:
Set the title in a clear and concise manner.
Create a meta description.
CSS Introduction
We need CSS to build a website, apply styles to it, and make it appear great.
HTML is merely the skeletal layout of a website.
What is CSS?
CSS stands for Cascading style sheets.
CSS is optional, yet it transforms a drab HTML page into a lovely, responsive
website.
body {
background-color: black;
}
This will make the background of your page black.
8
Getting Started
body {
color: white; - Declaration (property: value)
background : black; - Declaration
}
Element selector
It’s used to pick out an element based on its tagname.
h1 {
color: green;
}
Id selector
It’s used to find an element with a certain id.
# is used to target by id
#myId {
color: white;
background: black;
}
Class selector
It’s used to find an element that has a specific class.
* {
margin: 0;
padding: 0;
}
Comments in CSS
In CSS, comments are content that is not parsed and is thus disregarded.
/* This is comment */
What to do now?
Create a HTML page using all CSS selectors.
9
CSS rules are just selectors and key-value pairs. To alter color and set
backgrounds, we may use CSS rules.
Color property
The color property of CSS may be used to change the color of text within an
element.
h1 {
color: yellow; → Text color will be changed to yellow.
}
1. RGB: Specify color using Red, green, blue values, example, rgb(200, 98,
70).
2. HEX Code: Specify color using hex code, example, #00FF44.
3. HSL: Specify the color using hsl (hue saturation lightness) values,
example, hsl (8, 90%, 63%).
Any of these variables can be used to provide the color or background color
value.
Quick Point: For color, we also have RGBA and HSLA values, but they are rarely
utilized by novices. Alpha is represented by the letter A.
Background-color property
The CSS background-color attribute defines a container’s background color.
for example:
.green {
background-color: green;
}
Background-image property
To set a picture as the background, use this property.
h1 {
background-image: url("myimage.png");
}
Background-repeat property
repeat-x: repeat in horizontal direction.
repeat-y: repeat in vertical direction.
no-repeat: image not repeat.
Background-size property
cover: fits & no empty space remains.
contain: fits & image is fully visible.
auto: display in original size.
{{width}}: Set width, and height will be set automatically.
{{ width}} {{ height}}: Set width & height.
h1 {
background-position: left top;
}
h1 {
background - attachment: fixed;
}
Background Shorthand
Multiple background properties can be configured with a single property.
h1 {
background: yellow url("myimage.png") no-repeat fixed right top;
}
Given that the others are in sequence, one of the characteristics might be
missing.
What to do now?
Create a card with background image with given width and height.
Create a page with a fixed non scroll able background.
Tried out background shorthand properties.
10
All HTML elements are treated as boxes in the CSS box model.
https://edu.gcfglobal.org/en/basic-css/the-css-box-model/1/
#box {
height: 70px;
width : 70px;
}
Total height = height + top / bottom padding + top / bottom border + top /
bottom margin
.box {
margin: 3px;
padding: 4px;
}
.box {
margin: 2px(top) 0px(right) 2px(bottom) 1px(left);
}
.box {
margin: 7px(top & bottom) 3px(left & right);
}
margin-top: 10px;
margin-bottom: 3px;
margin-left: 8px;
margin-right: 5px;
Setting Borders
The border can be set as follows:
.border {
border-width: 1px;
border-style: solid;
border-color: red;
}
or just set
.border {
border: 2px solid red;
}
Border Radius
To generate rounded borders, we may adjust the border radius.
.radius {
border-radius: 12px;
}
Margin Collapse
The equal margin is the bigger of two margins from different elements when
they overlap. This is referred to as margin collapse.
Box Sizing
Determines how much padding and border is included in the width and height
of an element. It might be either a content-box or a border-box.
.boxsizing {
box-sizing: border-box;
}
here border-box means the content width and height includes content + padding +
border.
What to do now?
Add margin and padding or box-sizing property to content layout and practice
how to handle the spacing.
11
Display property
The CSS display property specifies whether an element is regarded as a block or
inline element, as well as the layout for its children.
display: inline
Only takes up the space that the element requires.
There are no line breaks before or after.
It is not possible to change the width or height of the image.
display: block
Takes up the entire width of the screen.
Before and after the element, a newline is left.
display: inline-block
Similar to inline, but with the ability to customize height, width, margin,
and padding.
Elements can be placed adjacent to one another.
display: none
The element is no longer included in the document flow.
Its space is free.
visibility: hidden
Although the element is hidden, its position is reserved.
text-align property
The horizontal alignment of a text can be set using this command.
text-decoration property
Used to decorate the text.
Can be overline, line-through, underline and none.
text-transform property
In a text, this is used to identify uppercase and lowercase letters.
line-height property
The gap between lines is specified using this property.
Font
The font used on a website has a significant impact on its appearance and feel.
font-family
A text’s typeface is specified by its font family.
As a “fallback” mechanism, it may contain numerous values.
Other than px, there are other units for describing size. There are percentages
such as rem, em, vw, and vh.
Relative lengths
These units are relative to the other length property. Following are some of the
most commonly used relative lengths.
1. em: Unit relative to the parent font size.
2. rem: Unit relative to the root font size. (<Html> tag)
3. vw: Unit relative to 1% view port width.
4. vh: Unit relative to 1 % view port height.
5. %: Unit relative to the parent element.
min/max-height/width property
CSS provides properties for min-height, max-height, min-width, and max-
width. The minimum height will be enforced if the content is less than the
minimum height. In the case of other linked properties, the situation is similar.
Position property
The following are the available values for manipulating an element’s location:
1. static: The top / bottom / left / right / z-index default positions have no
impact.
2. relative: The top / bottom / left / right / z-index buttons are now
functional. Otherwise, the element seems to be static in the document’s
flow.
3. absolute: The Element is taken out of the flow and positioned in relation to
its first non-static predecessor, top / bottom, and so on.
4. fixed: The element is positioned relative to the browser window, much like
absolute.
5. sticky: The location of the Element is determined by the user’s scroll
position.
z-index property
The z-index attribute indicates an element’s stack order. In the case of
overlapping items, it specifies which layer will be on top.
What to do now?
Create a sticky or fixed position navigation bar or header.
Practice different positions or relative lengths and z-index.
13
Flexbox
We’ll start with the float and clear attributes before moving on to CSS flexbox.
Float property
The float attribute is straightforward. It just moves the element to the left or
right.
Clear property
To clear the float, use this. It determines which items are allowed to float next
to a certain element.
CSS flexbox
Aims to improve the layout, alignment, and distribution of space among
elements in a container.
Container {
display: flex;
}
flex-direction property
Sets the direction in which objects are put down. It might be a row, a row-
reversed row, or a column column-reversed column.
Source: css-tricks.com/snippets/css/a-guide-to-flexbox/
.Container {
display: grid;
}
grid-row-gap property
Modify the spacing between the rows of a CSS grid.
grid-gap property
Shorthand property for grid-row-gap & grid-column-gap
.Container {
display: grid; grow
grid-gap: 10px(row) 20px(column);
}
What to do now?
Create a responsive web page using media query and content layout using
grids.
15
Rotate, move, skew, and scale items are all done via transforms. They’re
employed to generate a three-dimensional effect.
Transform property
To perform a 2D or 3D transformation to an element, use this command.
Transform-origin property
Allows you to move converted parts around.
2D transforms: can change x & y axis.
3D transforms: can change z axis as well.
CSS Transitions
Used to modify property values over time in a gradual manner.
Transition property
In CSS, the transition property is used to add transition. The properties for CSS
transition are as follows.
1. transition property: The property you want to transition.
2. transition-duration: Time for which you want transition to apply.
3. transition-timing-function: How you want the property to transition.
4. transition-delay: Specifies the delay for the transition.
All these properties can be set using a single shorthand property.
CSS Animations
Used to provide you greater control over how CSS attributes are animated. We
may utilise the @keyframes rule to modify the animation style from one to
another.
@keyframes animate {
from { width: 20px; } → Can change multiple properties
to { width: 40px; }
}
Properties to add Animations
The attributes needed to set animation in CSS are as follows:
1. animation-name: name of the animation.
2. animation-duration: How long does the animation run ?
3. animation-timing-function: Determines speed curve of the animation.
4. animation-delay: Delay for the start of an animation.
5. animation-iteration-count: Number of times an animation should run.
6. animation-direction: Specifies the direction of the animation.
@keyframes name {
0% {
width: 20px;
}
50% {
width: 50px;
}
100% {
width: 100px;
}
}
What to do now?
Create a progress bar animation with percentage and put animations in
images.
16
Projects
Mini-projects that may be done in a few days or hours are one of the finest
methods to practice HTML. Here are the greatest mini-projects to help you put
what you’ve learn into practice!
1. Navigation bar
A navigation bar makes it simple for people to find their way around. They may
be used to categories information by kind and provide connections to other
areas of a website. Navigation bars may be seen on websites such as Amazon,
Facebook, Reddit, and this one.
What you’ll learn: How to Make Use of Links, What Is The Best Way To Create A
Page Header? How to Make a Responsive Website (It will work on Mobile,
Desktop and Tablets) Bar of Navigation, How to Make a List, How to use CSS to
decorate a typeface and create a list?
3. Photo Gallery
While studying HTML and CSS, designing an image gallery page is an excellent
approach to practice constructing a website layout. A gallery is an excellent
venue for displaying your most recent work. This can be accomplished by the
use of an image wall, a grid of photos, or a slide show.
What you’ll learn: What is Grid Layout and how do I utilize it? How to Add
Images to a Web Page, How to Create a Responsive Website, How to Make a
Photo Card?
What you’ll learn: Responsive table design, text alignment, table column
freeze, and more. Fonts, Layout, and Design What is the difference between a
Div and a Paragraph?
What you’ll learn: How to create a column layout How to Add Images, How to
Use Grid Layout How to Use Various Heading Styles, Text Formatting, and
Table Layout?
6. Registration Form
A common HTML and CSS project is the registration form. It’s a simple
registration page with text boxes for login, password, email, and other
information. To fill in the information, the user must first select the “Show
Fields” option.
What you’ll learn: how to create a form, What are input and form fields, and
how do I utilise them? Alignment of content Elements can be shown or hidden,
and header and text layout can be changed.
Also by Vikalp Kaushik
https://www.amazon.com/dp/B09PHV9RZ1