Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Web Developer's Reference Guide

You're reading from   Web Developer's Reference Guide A one-stop guide to the essentials of web development including popular frameworks such as jQuery, Bootstrap, AngularJS, and Node.js

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781783552139
Length 838 pages
Edition 1st Edition
Arrow right icon
Authors (3):
Arrow left icon
Joshua Johanan Joshua Johanan
Author Profile Icon Joshua Johanan
Joshua Johanan
Talha Khan Talha Khan
Author Profile Icon Talha Khan
Talha Khan
Ricardo Zea Ricardo Zea
Author Profile Icon Ricardo Zea
Ricardo Zea
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. HTML Elements FREE CHAPTER 2. HTML Attributes 3. CSS Concepts and Applications 4. CSS Properties – Part 1 5. CSS Properties – Part 2 6. CSS Properties – Part 3 7. CSS Functions 8. JavaScript Implementations, Syntax Basics, and Variable Types 9. JavaScript Expressions, Operators, Statements, and Arrays 10. JavaScript Object-Oriented Programming 11. Extending JavaScript and ECMAScript 6 12. Server-side JavaScript – NodeJS 13. Bootstrap – The Stylish CSS Frontend Framework 14. jQuery – The Popular JavaScript Library 15. AngularJS – Google's In-Demand Framework Index

Document metadata

The next elements will give metadata about the document. In addition to this, you can also include links to resources, such as CSS and JavaScript.

head

The head element is the metadata parent element. All other metadata elements will be children of this element:

<head></head>

Description

The head element usually must have a title element inside it. The elements that can go in head are title, link, meta, style, script, noscript, and base. These elements are explained next.

Here is an example of the head element that defines a title and stylesheet element:

<head>
    <title>Title that appears as the tab name</title>
    <link href="style.css" rel="stylesheet" type="text/css" media="all" />
</head>

title

The title element displays the title of the document. This is what is displayed in the browser's tab or the browser window:

<title></title>

Description

The title element is an aptly named element. This is a required element in head, and there should only be one title element for a document. Here is a simple example of title element:

<head>
    <title>Example</title>
</head>

link

The link element links a resource to the current document:

<link crossorigin href media rel sizes type></link>

Attributes

The attributes that are used in the link element are as follows:

  • crossorigin: This tells the browser whether to make the Cross-Origin Resource Sharing (CORS) request or not
  • href: This indicates the URL of the resource
  • media: This selects the media that this resource applies to
  • rel: This indicates the relationship of this resource to the document
  • sizes: This is used with rel when it is set to icons
  • type: This indicates the type of content of the resource

Description

The link element has a lot of attributes, but most of the time, it is used for loading the CSS resources. This means that you will want to use the attributes href, rel, type, and media at least.

You can have multiple link elements in a head element. Here is a simple example of how to load CSS:

<link href="style.css" rel="stylesheet" type="text/css" media="all" />
<link href="style.css" media="screen" rel="styleshhet" sizes type="text/css"></link>

See also

You can also refer to the crossorigin, href, media, rel, sizes, and type attributes to find out more details about the title element.

meta

The meta element contains metadata about the document. The syntax is as follows:

<meta content http-equiv name></meta>

Attributes

The attributes that are used in the meta element are as follows:

  • content: This states the value of either the name or http-equiv attribute.
  • http-equiv: This attribute, in the case of HTML5, can be set to default-style, which sets the default style. Alternatively, it can be set to refresh, which can specify the number of seconds taken to refresh the page and a different URL for the new page if needed, for example, http-equiv="1;url=http://www.google.com".
  • name: This states the name of the metadata.

Description

The meta tag has many nonstandard applications. The standardized applications can be viewed in Chapter 2, HTML Attributes.

Note

Apple has many meta tags that will pass information to an iOS device. You can set a reference to an App Store application, set an icon, or display the page in the full screen mode, as just a few examples. All of these tags are nonstandard, but useful when targeting iOS devices. This is true for many other sites and companies.

You can use multiple meta tags in a head element. Here are two examples. The first example will refresh the page every 5 seconds and the other will define the author metadata:

<meta http-equiv="refresh" content="5" />
<meta name="author" content="Joshua" />

See also

You can also refer to the name attribute to find out more details about the meta element.

style

The style element contains the style information.

CSS:

<style media scoped type></style>

Attributes

The attributes that are used in the style element are as follows:

  • media: This is a media query
  • scoped: The styles contained in this element only apply to the parent element
  • type: This sets the type of document; the default value is text/css

Description

The style element is usually in the head element. This allows you to define CSS styles for the current document.

The preferred method of using CSS is to create a separate resource and use the link element. This allows styles to be defined once and used everywhere on a website instead of defining them on every page. This is a best practice as it allows us to define the styles in one spot. We can then easily find and change styles.

Here is a simple inline stylesheet that sets the font color to blue:

<style media="screen" scoped type="text/css">
    body{
        color: #0000FF;
    }
</style>

See also

You can also refer to the global attributes and Chapters 3-7 to know more details about the style element.

base

The base element is the base URL for the document. The syntax is as follows:

<base href target>

Attributes

The attributes that are used in the base element are as follows:

  • href: This indicates the URL to be used as the base URL
  • target: This indicates the default target to be used with the URL

Description

The base URL is used whenever a relative path or URL is used on a page. If this is not set, the browser will use the current URL as the base URL.

Here is an example of how to set the base URL:

<base href="http://www.packtpub.com/">

See also

You can also refer to the target attribute to find out more details about the base element.

script

The script element allows you to reference or create a script for the document:

<script async crossorigin defer src type><script>

Attributes

The attributes that are used in the script element are as follows:

  • async: This is a Boolean attribute that tells the browser to process this script asynchronously. This only applies to the referenced scripts.
  • crossorigin: This tells the browser whether to make a CORS request or not.
  • defer: This is a Boolean attribute that tells the browser to execute the script after the document has been parsed.
  • src: This distinguishes the URL of the script.
  • type: This defines the type of the script that defaults to JavaScript if the attribute is omitted.

Description

The script element is the way to get JavaScript into your document and add enhanced interactivity. This can be done using a bare script tag and adding JavaScript into the element. Also, you can use the src attribute to reference an external script. It is considered a best practice to reference a script file as it can be reused here.

This element can be a child of head or can be placed anywhere in the body of the document. Depending on where the script element is located, you may or may not have access to the DOM.

Here are two examples of using a script element. The first example will reference an external script, the second will be an inline script element, and the last will show how to use the crossorigin attribute:

<script src="example.js" type="text/javascript"></script>
<script>
    var a = 123;
</script>
<script async crossorigin="anonymous" defer src="application.js" type="text/javascript"><script>

noscript

The noscript element will be parsed if scripting is turned off in the browser. The syntax is as follows:

<noscript></noscript>

Description

If scripting is enabled, the content inside of this element will not appear on the page and the code inside it will run. If scripting is disabled, it will be parsed.

This element is mainly used to let the user know that the site may not work with JavaScript. Almost every website today not only uses JavaScript, but requires it.

Here is an example of the noscript element:

<noscript>
    Please enable JavaScript.
</noscript>
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Web Developer's Reference Guide
You have been reading a chapter from
Web Developer's Reference Guide
Published in: Mar 2016
Publisher:
ISBN-13: 9781783552139
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon