Lecture 1 HTML & Css
Lecture 1 HTML & Css
Shermeen Adnan
Web Development Careers
• Front-End Developer
– The front end of a website is the part that users
interact with. Everything that you see when you’re
navigating around the Internet, from fonts and
colors to dropdown menus and sliders, is a combo
of HTML, CSS, and JavaScript being controlled by
your computer’s browser.
Front-End Developer
• SKILLS AND TOOLS
– front-end devs must be adept at three main languages:
• HTML
• CSS
• Javascript programming
– In addition to fluency in these languages, front-end devs need to be familiar with
frameworks to ensure great-looking content no matter the device
• Bootstrap
• Foundation
• Backbone
• AngularJS
• EmberJS
– Libraries which package code into a more useful, time-saving form.
• jQuery
• LESS
– A lot of front-end developer job listings also call for experience with Ajax, a widely
used technique for using Javascript that lets pages dynamically load by downloading
server data in the background.
Front-End Developer
• HOW IT TRANSLATES
– Everything you’re seeing on this website right now
was made possible by a front-end developer. A
designer crafted the logo and graphics, a
photographer took the pictures, and a copywriter
wrote the text. But a front-end dev assembled all
of those pieces, translated them into web-speak,
and built the experience you have with each page.
Web Development Careers
• Back-End Developer
– So what makes the front end of a website possible?
– Where is all that data stored?
– This is where the back end comes in.
– The back end of a website consists of a server, an
application, and a database.
– A back-end developer builds and maintains the
technology that powers those components which,
together, enable the user-facing side of the website to
even exist in the first place.
Back-End Developer
• SKILLS AND TOOLS
– In order to make the server, application, and database communicate with
each other, back-end devs use server-side languages to build an application
• PHP
• Ruby
• Python
• Java
• .Net
– And tools like
• MySQL
• Oracle
• SQL Server to find, save, or change data and serve it back to the user in front-end code.
– Job openings for back-end developers often also call for experience with PHP
frameworks like Zend, Symfony, and CakePHP; experience with version
control software like SVN, CVS, or Git; and experience with Linux as a
development and deployment system.
Back-End Developer
• HOW IT TRANSLATES
– When you navigated to this website, the servers
sent information to your computer or mobile
device, which turned into the page you’re seeing
right now. That process is the result of a back-end
developer’s work. In addition, the storage of your
personal information—and the fact that each time
you return to the site and log in, your data is
called up—is attributable to a back-end developer.
Web Development Careers
• Full Stack Developer
– full stack developers are jacks-of-all-trades
Best Text Editors in 2019
• Visual Studio Code (free)
• Sublime Text (paid)
• Atom (freehtml)
Sublime Text
• www.sublimetext.com
• Toolsbuild systemnew build system
• Paste this
"cmd": ["C:\\Program Files
(x86)\\Google\\Chrome\\Application\\chrome
.exe", "$file"]
• Save with name chrome browser
Full Stack Web Application Architecture
HTML
• What is HTML?
– Hyper Text Markup Language
• used to create web pages as well as other types of documents viewable
in a web browser.
• describes the structure of Web pages using markup
– HTML is a standard specified and maintained by World Wide
Web Consortium(W3C).
– Older version of HTML
• HTML4.01
• XHTML1.0
– Present version of HTML
• HTML5
– Next version of HTML is HTML 5.2/ 5.3, which is under
development but developers have already started using some of
its features.
HTML5
• Tools required
– Browser
– Text editor
• New elements
– audio
– video
• Frequently used terms
– Tag
– Element
– Attribute
HTML5: HTML Tags
• HTML tags are element names surrounded by angle brackets:
– <tagname>content goes here...</tagname>
• HTML tags normally come in pairs like <p> and </p>
• The first tag in a pair is the start tag, the second tag is the end
tag
• The end tag is written like the start tag, but with a forward
slash inserted before the tag name
• There are few element which do not have an end tag and
have no content, they are called empty elements like <br>
(which indicates a line break), <meta>
• The start tag is also called the opening tag, and the end tag
the closing tag.
HTML5: Attribute
• All HTML elements can have attributes
• Attributes provide additional information about an element
• Attributes are always specified in the start tag
• Attributes usually come in name/value pairs like: name="value“
• The href Attribute
– HTML links are defined with the <a> tag. The link address is specified
in the href attribute:
– Example: <a href="https://www.w3schools.com">This is a link</a>
• The src Attribute
– HTML images are defined with the <img> tag.
– The filename of the image source is specified in the src attribute:
– Example : <img src="img_girl.jpg“>
HTML5: Attribute
• Relative address
– img_girl.jpg
– images/img_girl.jpg
– ../img_girl.jpg
• Absolute address
– https://www.w3schools.com/images/img_girl.jpg
HTML5: Attribute
• The width and height Attributes
– Images in HTML have a set of size attributes, which specifies
the width and height of the image:
– Example
• <img src="img_girl.jpg" width="500" height="600">
– The image size is specified in pixels: width="500" means 500
pixels wide.
• The style Attribute
– The style attribute is used to specify the styling of an
element, like color, font, size etc.
– Example : <p style="color:red">I am a paragraph</p>
HTML5: Attribute
• The alt Attribute
– The alt attribute specifies an alternative text to be used, when an
image cannot be displayed.
– The value of the attribute can be read by screen readers. This way,
someone "listening" to the webpage, e.g. a vision impaired person,
can "hear" the element.
– Example
• <img src="img_girl.jpg" alt="Girl with a jacket">
– The alt attribute is also useful if the image does not exist:
– Example
– See what happens if we try to display an image that does not exist:
• <img src="img_typo.jpg" alt="Girl with a jacket">
HTML5: Attribute
• The lang Attribute
– The language of the document can be declared in the <html> tag.
– The language is declared with the lang attribute.
– Declaring a language is important for accessibility applications (screen
readers) and search engines:
• <!DOCTYPE html>
<html lang="en-US">
<body>
...
</body>
</html>
– The first two letters specify the language (en). If there is a dialect, use two
more letters (US).
HTML5: Attribute
• The title Attribute
– Here, a title attribute is added to the <p> element.
The value of the title attribute will be displayed as
a tooltip when you mouse over the paragraph:
– Example
• <p title="I'm a tooltip">
This is a paragraph.
</p>
HTML5: Attribute
• Suggestions
– Use Lowercase Attributes
– Quote Attribute Values
– Single or Double Quotes?
– Double quotes around attribute values are the most
common in HTML, but single quotes can also be used.
– In some situations, when the attribute value itself contains
double quotes, it is necessary to use single quotes:
• <p title='John "ShotGun" Nelson'>
– Or vice versa:
• <p title="John 'ShotGun' Nelson">
HTML5: Attribute
• Below is an alphabetical list of some attributes often used in
HTML:
• https://www.w3schools.com/tags/ref_attributes.asp
• https://www.w3schools.com/tags/default.asp
HTML5 Example
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta name=“description” content=“keywords related to web page”>
<title>Page Title</title>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
<!DOCTYPE html>
• The <!DOCTYPE html> declaration defines this
document to be HTML5
• The <!DOCTYPE> declaration represents the
document type, and helps browsers to display
web pages correctly.
• It must only appear once, at the top of the page
(before any HTML tags).
• The <!DOCTYPE> declaration is not case
sensitive.
<html>……….</html>
• <html> root element of HTML document & rest of
code is located between the HTML tag
– lang attribute helps search engines return language
specific results, and it is also used by screen readers
that switch language profiles to provide the correct
accent and pronunciation speech synthesis tools with
pronunciation
• <html> has 2 sections
– <head> …….. </head>
– <body> …….. </body>
How to View HTML Source?
• Have you ever seen a Web page and wondered "Hey! How
did they do that?"
• View HTML Source Code:
– Right-click in an HTML page and select "View Page Source" (in
Chrome) or "View Source" (in IE), or similar in other browsers.
This will open a window containing the HTML source code of the
page.
• Inspect an HTML Element:
– Right-click on an element (or a blank area), and choose "Inspect"
or "Inspect Element" to see what elements are made up of (you
will see both the HTML and the CSS). You can also edit the HTML
or CSS on-the-fly in the Elements or Styles panel that opens.
<head>……….</head>
• The <head> element is a container for metadata.
• Metadata is data (information) about data.
• Provides metadata about the HTML document. Metadata will not be
displayed on the page, but will be machine parse able.
• Meta elements are typically used to specify page description, keywords,
author of the document, last modified, and other metadata.
• Metadata typically define the document title, character set, styles,
links, scripts, and other meta information.
• head element defines the head section which contains information
about the html document
– <meta>
– <title> ………. </title>
– <link> Include CSS stylesheets
– <script> Used to add Javascript to a page (can be used in body as well)
<head>……….</head>
• <head>
<meta charset="UTF-8">
<meta name="author" content="John Doe“>
<meta name="viewport" content="width=device-width, initial-
scale=1.0“>
very important
<meta name="description" content="Free Web tutorials“>
Obsolete
<meta name="keywords" content="HTML,CSS,XML,JavaScript“>
• </head>
<head>……….</head>
• Setting The Viewport
• HTML5 introduced a method to let web designers take control over the
viewport, through the <meta> tag.
• The viewport is the user's visible area of a web page. It varies with the
device, and will be smaller on a mobile phone than on a computer
screen.
– You should include the following <meta> viewport element in all your web
pages:
• <meta name="viewport" content="width=device-width, initial-scale=1.0">
– A <meta> viewport element gives the browser instructions on how to control the
page's dimensions and scaling.
– The width=device-width part sets the width of the page to follow the screen-
width of the device (which will vary depending on the device).
– The initial-scale=1.0 part sets the initial zoom level when the page is first loaded
by the browser.
– Here is an example of a web page without the viewport meta tag, and the same
web page with the viewport meta tag:
<head>……….</head>
• <title> …………. </title>
– The HTML <title> tag is used for declaring
the title, or name, of the HTML document.
– The title is usually displayed in the
browser's title bar (at the top).
– It is also displayed in browser bookmarks and
search results.
– The title tag is placed between the opening and
closing <head> tags
<body>……….</body>
• Body element defines the body section which
contains the main content of html document
• This is where we put information which is
being displayed in browser
HTML Headings
• Headings Are Important
– HTML headings are defined with the <h1> to <h6> tags.
– Search engines use the headings to index the structure and content
of your web pages.
– Users skim your pages by its headings. It is important to use
headings to show the document structure.
– <h1> defines the most important heading. <h6> defines the least
important heading.
– <h1> headings should be used for main headings, followed
by <h2> headings, then the less important<h3>, and so on.
• Note: Use HTML headings for headings only. Don't use
headings to make text BIG or bold.
HTML Headings
• Example
– <h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
• Bigger Headings
– Each HTML heading has a default size. However, you can specify the size
for any heading with the style attribute, using the CSS font-size property:
– Example : <h1 style="font-size:60px;">Heading 1</h1>
• Note: Browsers automatically add some white space (a margin)
before and after a heading.
HTML Headings
• HTML Horizontal Rules
– The <hr> tag defines a thematic break in an HTML page,
and is most often displayed as a horizontal rule.
– The <hr> element is used to separate content (or define a
change) in an HTML page:
– Example
• <h1>This is heading 1</h1>
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>
HTML Paragraphs
• HTML paragraphs are defined with the <p> tag:
• Example
– <p>This is a paragraph.</p>
<p>This is another paragraph.</p>
• Browsers automatically add some white space (a margin) before
and after a paragraph.
• HTML Display
– You cannot be sure how HTML will be displayed.
– Large or small screens, and resized windows will create different results.
– With HTML, you cannot change the output by adding extra spaces or
extra lines in your HTML code.
– The browser will remove any extra spaces and extra lines when the page
is displayed:
• Dropping the end tag can produce unexpected results or errors.
HTML Comments <!--...-->
• The comment tag is used to insert comments in the source code.
• Comments are not displayed in the browsers, but they can help
document your HTML source code. .
• You can use comments to explain your code, which can help you
when you edit the source code at a later date. This is especially
useful if you have a lot of code.
• You can also use the comment tag to "hide" scripts from
browsers without support for scripts (so they don't show them
as plain text)
• Comments are also great for debugging HTML, because you can
comment out HTML lines of code, one at a time, to search for
errors
• Example
– <!--This is a comment. Comments are not displayed in the browser-->
HTML Comments
• Example
– <script type="text/javascript">
<!--
function displayMsg() {
alert("Hello World!")
}
//-->
</script>
• Note: The two forward slashes at the end of
comment line (//) is the JavaScript comment symbol.
This prevents JavaScript from executing the --> tag.
HTML Line Breaks
• The HTML <br> element defines a line break.
• Use <br> if you want a line break (a new line)
without starting a new paragraph:
• Example
– <p>This is<br>a paragraph<br>with line
breaks.</p>
• The <br> tag is an empty tag, which means
that it has no end tag.
The HTML <pre> Element
• The HTML <pre> element defines preformatted text.
• The text inside a <pre> element is displayed in a fixed-width font
(usually Courier), and it preserves both spaces and line breaks:
• Example
– <pre>
My Bonnie lies over the ocean.