Overall Structure & Features
doctype,html(with language attribute),head,body; all with proper alignment and indentation- HTML Comments (
<!-- -->):- Header Comments:
- Coder initials
- Date
- Site
- Filename
- General Documentation including possible attributions if necessary
- Organizational/Documentation Comments:
- Mark end of large blocks of code (especially
divs) - Contextual attributions/clarifications
- Mark end of large blocks of code (especially
- Header Comments:
- Uniform indentation showing clear parent, child, sibling relationships
- Use lowercase when creating elements and using attribute names: for example:
<body>, not<BODY> - Whenever possible use semantic HTML markup. For example:
<header>,<main>,<nav>,<main>,<footer> - Meaningful identifier names (like
classoridnames):- Self-documenting
- Consistent casing
- Avoid 'reserved word' type names
- Date stamp of last page update (a likely JavaScript feature) often in the
<footer>area - HTML and CSS Validation
Head
- Meaningful
<title>content - Organizational commments and groupings
charsetand responsive<meta>tags- Bootstrap CSS
<link>s - Developer Styles CSS
<link>s - Favicon code
- Google Fonts: 2-4 per site
- Page-level
<style>block - Possible
<script>block for JavaScript - There should never be web page content in the webpage document head!
Body Content
Many issues we list here are addressed when you make sure you page validates
- Responsiveness is an important, yet illusive design goal. Bootstrap assists greatly with its implementation.
- Review basic formatting standards
- Let's say it again: use semantic markup whenever possible. More examples:
<ul>,<ol>,<blockquote>,<form>,<details>,<summary>,<section> - Use predominantly sans-serif fonts; serif fonts are ok for accents
- Avoid the heavy use of 'boxing' content
- Spel chek your content!, (wink)
- CSS Borders can be a useful alternative to
<hr>tags (horizontal lines) - General layout:
- It would be unusual not to have the bulk of a web page's content centered in browser and styled for a reasonable width
- Showcase page content by using a muted background/pattern/gradient for the HTML background
- Images:
- Typically should have a meaningful, contextual, unique id (for styling and/or programmatic purposes)
- Must have an
alt attributefor validation - Should only be sized with CSS, not width or height attributes
Quite a figure! - Consider putting them in a
figuretag for additional control and the ability to add captions title attributes can convey additional content without cluttering the page (screen tips aka tool tips)
- Links:
- Avoid underlining: use other styling techniques to draw attention to them
- Don't forget to use pseudo classes for additional attention-getting techniques
We love links! - Rely heavily on
title attributes to convey additional information about what the link does - The
target="_blank"attribute can open a link in a new page. This is preferred when directing traffic to a webpage that is 'off-site.' - Copy/paste URLs into your hyperlinks and always double-check that a link takes you to the proper location
- Contextual hyperlinks can educate and provide additional resources to keep your page from being cluttered. See the example below about using Bootstrap5 to style tables
- Did you see what we did in the previous list item? We inserted a page-level link to other content within the page. In this case we linked to:
href="#bst"which 'warped' us to a list item with that specific id:id="bst". Wow! Just use a '#' in front of an id in anhrefand you're in business!
- Lists:
- Ordered lists provide their own numbering; don't put any in yourself
- Nested lists must be a part of a specific nested list item (an
<li>) otherwise the page won't validate - You can provide your own bullets in an unordered list. Here's a grave example if you're brave enough to dig around for it
- Unordered lists are often styled to provide masthead and/or footer navigation. In a masthead, they are often nested in a
<nav>tag - Remember: people skim webpages like billboards - they don't read them like books. Lists can simplify content
- Tables:
- Study and follow basic HTML table anatomy at W3Schools
- Tables are rarely used for structuring/arranging elements on a webpage. CSS is used to do that
- Bootstrap5 offers lots of help with styling tables
<div>s:- If you are able to implement a
<div>without aclassorid, you should question whether you really needed it - Ask: "Can I use a semantic element rather than a
<div>?" - Remember: Bootstrap relies heavily on
<div>s with classes
- If you are able to implement a
- Preformatted content:
- Flair:
<span>elements, styled with CSS classes- HTML Entities such as 'curly quotes' can add nice touches and programmatic stability with alternatives for symbols that are used in code (like, <)
- The
<abbr>tag can reduce 'bloat' in a page by providing information about an acronym with a hover, using thetitleattribute. It can be styled according to your preferences.
Coding
- General:
- When copy/pasting source code, take pains to eliminate 'orphaned' code: If you wind up not using something in your application, get rid of it
- Err on the side of attributing your sources with internal documentation
- Find a syntactual coding style that works for you and stick with it: camelCase? under_score? Stick with conventional syntax however, that is respected by the coding community
IfWhen you copy/paste content, make sure you change what needs to be changed!- DWR! Sometimes copy/pasted code in VSCode inserts an extra closing tag in the document
- HTML: Write this content first, obviously, since it forms the structure of the webpage
- The HTML Style Guide from W3Schools offers useful tips on creating managable pages. Some of the big-ticket items:
- Quote attribute values
- Separate attributes by a single space
- Avoid spaces between the '=' in an attribute
- Be consistent in your structure
- For readability, add blank lines to separate large or logical code blocks
- A given element can only have one
classattribute. If multiple classes are needed, they are simply separated by spaces in a single attribute. - Remember,
titlecan be a tag (in the head) or an attribute (in the body of the page, within a tag element).
- The HTML Style Guide from W3Schools offers useful tips on creating managable pages. Some of the big-ticket items:
- CSS: This content follows HTML since it provides the style for the structure
- CSS is a powerful framework for making webpages look nice; it's an art and a science and takes some time to learn
- Generally, CSS should be used for styling rather than using HTML style attributes. Those have their place but can be limiting and inflexible.
- During development, it's sometimes convenient to do all the styling on the HTML page in a
styleblock and then port the styles to an external style sheet at a later time - There are vast number of CSS 'selectors' that let you target what you want to style. Watch a helpful video to learn more and while there, download the CSS selector cheat sheet.
- It's common to style away all default HTML styling with a wildcard selector (*) and then put in the style choices you want
- Use this format for most CSS rules:
body{ background-color: lightgrey; font-family: "Arial Black", Helvetica, sans-serif; font-size: 16em; color: black; } - Multi-word properties are hyphenated
- One-liners are acceptable in CSS for short rules
- Separate rules by a blank line
- CSS Templates can accelerate your project development!
- JavaScript: This content provides behavior for the page and creates a dynamic, rather than a static feel for the page