Coding format is crucial for front-end development, and HTML is the foundation of it all. A well-structured HTML document is essential for readability and maintainability.
Indentation is key in HTML, with each level of nesting indented four spaces. This makes it easy to see the structure of the document.
A consistent naming convention is also important, with element names and IDs following a logical pattern. In the article, we discussed how to use a consistent naming convention for HTML elements.
Using a consistent naming convention helps prevent naming conflicts and makes the code easier to understand.
HTML Formatting and Editing
HTML formatting can be achieved using the Format Document command in VS Code, which is based on js-beautify. This command can be accessed by pressing ⇧⌥F (Windows Shift+Alt+F, Linux Ctrl+Shift+I).
The HTML formatter offers various options, including setting the maximum amount of characters per line and specifying tags that shouldn't be reformatted. You can find these options in the VS Code settings under the html.format section.
To preserve line breaks before elements, you can set html.format.preserveNewLines to true. This can be particularly useful when working with preformatted text or code blocks.
Additional reading: Edit Html Code
Formatting
Formatting your HTML code is crucial to improve readability and maintainability. You can use the Format Document command to format the entire file or Format Selection to just format the selected text.
The HTML formatter is based on js-beautify, which offers various formatting options. These options can be accessed through the VS Code settings, including html.format.wrapLineLength, html.format.unformatted, and html.format.contentUnformatted.
To customize the formatting, you can adjust the settings to suit your needs. For example, you can set html.format.extraLiners to list the tags that should have an extra newline before them.
The formatter can be turned off by setting "html.format.enable": false in your settings. This allows you to use a different formatter if you prefer.
Here are some key settings to consider:
- html.format.wrapLineLength: Maximum amount of characters per line.
- html.format.unformatted: List of tags that shouldn't be reformatted.
- html.format.contentUnformatted: List of tags, comma separated, where the content shouldn't be reformatted.
- html.format.extraLiners: List of tags that should have an extra newline before them.
Note that embedded JavaScript is formatted unless 'script' tags are excluded. If you want to use a different formatter, you can define "html.format.enable": false in your settings to turn off the built-in formatter.
Auto Update Tags
Auto Update Tags is a feature that can save you a lot of time and effort when editing HTML code.
Linked editing is how it works, automatically updating the matching closing tag whenever you modify a tag. This feature is optional, and you can enable it by setting.
This means you don't have to manually update the closing tag every time you make a change, which can be a real time-saver.
Color Picker
The color picker is a powerful tool in HTML formatting and editing. It allows you to configure the hue, saturation, and opacity of the color picked up from the editor.
You can also trigger between different color modes by clicking on the color string at the top of the picker. This gives you more control over the color palette.
The picker appears on a hover when you are over a color definition, making it easy to access and adjust colors as you work.
For more insights, see: Coding for Background Color in Html
HTML Extensions and Customization
You can enhance VS Code's HTML support by using a declarative custom data format, which allows you to provide a list of JSON files that follow the custom data format. This will enable language support such as completion and hover information for new HTML tags, attributes, and attribute values.
To take your HTML coding to the next level, consider installing an extension from the Extensions view. Simply type 'html' to see a list of relevant extensions that can help with creating and editing HTML.
Some popular extensions include CSS, SCSS, and Less, which offer first-class support for CSS, including Less and SCSS. Emmet is another powerful tool that provides a wide range of features for web developers.
Here are some popular extensions for HTML:
- CSS, SCSS, and Less - VS Code has first-class support for CSS, including Less and SCSS.
- Emmet - Learn about VS Code's powerful built-in Emmet support.
If you're not sure which extension to choose, you can read the description and reviews to make an informed decision.
Frequently Asked Questions
What is the HTML file format?
An HTML file is the foundation of a website, using a markup language to describe elements with tags. It's a technical language that enables hypertext, linking related texts and graphics together.
What is the format of writing HTML?
HTML documents start with a document type declaration and are structured within tags, with the visible content contained between
tagsSources
- World Wide Web Consortium (w3.org)
- js-beautify (npmjs.com)
- Emmet snippet (emmet.io)
- Emmet cheat sheet (emmet.io)
- custom data format (github.com)
- Emmet official documentation (emmet.io)
- Wikipedia entry for HTML email (wikipedia.org)
- 1992 description of HTML tags (cern.ch)
- first W3C Recommendation for HTML5 (w3.org)
- the History clause (w3.org)
- 2004 position paper from the Mozilla Foundation and Opera Software (w3.org)
- WHATWG (whatwg.org)
- XHTML 1.0 (w3.org)
- HTML 4.01 (w3.org)
- HTML 4.0 (w3.org)
- HTML 3.2 Reference Specification (w3.org)
- W3C (w3.org)
- RFC 1866: Hypertext Markup Language 2.0 (ietf.org)
- Tim Berners-Lee (w3.org)
- ISO/IEC 8859-1 (wikipedia.org)
- US ASCII (wikipedia.org)
- Can I Use? (caniuse.com)
- Encrypted Media Extensions (w3.org)
- HTML and fuzzy validity (garymcgath.com)
- 3.2.5.2.1 Metadata content in the WHATWG HTML specification (whatwg.org)
- 3.2.4.2.1 Metadata content in HTML 5.2 (w3.org)
- MetaExtensions (whatwg.org)
- World Wide Web Technology Surveys (w3techs.com)
- Wikipedia List of HTML Editors (wikipedia.org)
- MDN element page for audio (mozilla.org)
- WHATWG Living Standard for HTML (whatwg.org)
- latest W3C snapshot of HTML 5 (w3.org)
- Community Group for Math on Web Pages (w3c.github.io)
- single-page presentation of the MathML specification with embedded MathML for examples (w3.org)
- Can I Use? (caniuse.com)
- clause 4.7.17. MathML (w3.org)
- HTML table element (whatwg.org)
- W3C Recommendation for CSS 1.0 (w3.org)
- HTML 2.0, RFC 1866 (ietf.org)
- proposed in October 1994 by Håkon Lie (w3.org)
- Universal Character Set (UCS), standardized as ISO 10646 (wikipedia.org)
- RFC 2070: HTML Internationalization (ietf.org)
- WorldWideWeb: Proposal for a HyperText Project (w3.org)
- https://www.iana.org/assignments/media-types/text/html (iana.org)
- HTML5 Video at Netflix (medium.com)
- HTML 4.0 (December 1997, revised April 1998) | HTML 4.0 Specification (w3.org)
- W3C blog | Fast-forwarding media support on the Web (5 February 2018) (w3.org)
- W3C | Recommended Doctype Declarations to use in your Web document. (w3.org)
- Wikipedia entry for XHTML (wikipedia.org)
- Here's Why There Are Different Versions of HTML (lifewire.com)
- W3C | The HTML Landscape. 18 August 2016 (w3.org)
- Archive Team page for HTML (archiveteam.org)
- Wikipedia entry for HTML (wikipedia.org)
- [HTML] - How to Make Text Italics in HTML (shecodes.io)
- HTML Encode (freewebtoolkit.com)
- Text HTML entities Convertor (online-toolz.com)
- Prismjs (prismjs.com)
Featured Images: pexels.com