Visual Studio Code provides basic support for HTML programming out of the box. There is syntax highlighting, smart completions with IntelliSense, and customizable formatting. VS Code also includes great Emmet support.
It supports configuration of hue, saturation and opacity for the color that is picked up from the editor. It also provides the ability to trigger between different color modes by clicking on the color string at the top of the picker. The picker appears on a hover when you are over a color definition.
You can fold regions of source code using the folding icons on the gutter between line numbers and line start. Folding regions are available for all HTML elements for multiline comments in the source code.
Tip: The formatter doesn't format the tags listed in the html.format.unformatted and html.format.contentUnformatted settings. Embedded JavaScript is formatted unless 'script' tags are excluded.
If you'd like to use HTML Emmet abbreviations with other languages, you can associate one of the Emmet modes (such as css, html) with other languages with the emmet.includeLanguages setting. The setting takes a language identifier and associates it with the language ID of an Emmet supported mode.
You can extend VS Code's HTML support through a declarative custom data format. By setting html.customData to a list of JSON files following the custom data format, you can enhance VS Code's understanding of new HTML tags, attributes and attribute values. VS Code will then offer language support such as completion & hover information for the provided tags, attributes and attribute values.
Visual Studio Code, often abbreviated as VS Code, is an open-source code editor developed by Microsoft. It supports a variety of programming languages, including HTML (HyperText Markup Language), which is the standard markup language for documents designed to be displayed in a web browser.
In this context, 'markup language' means a system for annotating a document in a way that is visually distinguishable from the content. Think of it like marking up a script for a play where you highlight different characters' lines in different colors. HTML helps determine the structure and layout of a web page, much like how an architect's blueprint determines the layout of a building.
This is a basic HTML document structure. It includes a declaration (which tells the browser that this is an HTML5 document), an element (which contains the whole HTML document), a element (which contains meta-information about the document), a element (which specifies a title for the document), and a element (which contains the document's content).
You don't "run" HTML code in the same way you run programs written in languages like Python or JavaScript. HTML is a static language, meaning the browser reads the file and renders the content as described by the HTML tags.
If you don't see the 'Open with Live Server' option, it means you need to install the Live Server extension. Go to the Extensions view (the square icon on the left sidebar), search for 'Live Server' and click Install. This handy extension allows you to run a local development server and live reload feature for static and dynamic pages.
One of the great features of using VS Code and Live Server is the ability to see your changes in real time. When you make changes to your HTML file in VS Code, those changes are immediately reflected in your browser.
Congratulations! You've now learned how to write and run HTML code in Visual Studio Code. Remember, programming is a skill that improves with practice. Don't be afraid to experiment with different HTML tags and attributes to see how they affect the look of your webpage. Happy coding!
Remember, understanding HTML and being comfortable with VS Code is the first step towards web development. As you become more confident, you can start exploring other technologies such as CSS (Cascading Style Sheets) and JavaScript to add style and interactivity to your web pages.
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Recently, I finished the videos regarding "Adding Images to the Page" in the HTML section of Treehouse. I went onto my editor (Visual Studio Code), though, to try it on my own, and I couldn't figure out how to move a picture from my computer onto the practice website I was trying to build.
So assuming you've created a .html document in Visual Studio Code with the necessary markup, you can add images to your own practice page by using the tag. You can then define the location of the image using the src attribute within that tag.
Keep in mind that in this instance, the .html document should be located in the parent directory of the images folder. If the image is located in the same folder as the .html document, you would simply use the file name like so:
To open DevTools in Visual Studio Code in Debug mode by using the DevTools UI, right-click an .html file or click the Launch Project button, as described in Opening DevTools and the DevTools browser. You can also use the Visual Studio Code UI for launching the Debugger, such as F5, to open the DevTools tabs as well, if you define a DevTools-compatible launch.json file by clicking the Generate launch.json button in the Microsoft Edge Tools Side Bar.
Right-click an .html file in Explorer > Open with Edge. This approach essentially uses a file path rather than a URL, and doesn't require you to generate a launch.json file.
You can open the Edge DevTools: Browser tab (the embedded DevTools browser) as part of a debugging session. The DevTools extension opens a new browser as an embedded browser in Visual Studio Code. This Devtools: Browser tab can be moved anywhere within the editor. You can use this tab side by side with your source code, or split the panes and have the browser preview below your code:
You can use the DevTools extension with the usual Visual Studio Code debugging UI/workflow, as follows. In this approach, to enter Debug mode, we are not using the DevTools UI; we are not right-clicking an .html file to select Open with Edge, and we are not clicking the Activity Bar > Microsoft Edge Tools > Launch Project button.
JavaScript debugging is built in to Visual Studio Code; you can debug in Chrome, Microsoft Edge, or Node.js without installing extensions. If you debug by using the Microsoft Edge option with the Visual Studio Code debugging features and UI, you can start Microsoft Edge DevTools from the JavaScript debugger. If the DevTools extension isn't installed, you're prompted to optionally install it.
The DevTools extension gives additional functionality, such as the embedded DevTools browser which has a Device Emulation toolbar, and provides additional ways to enter Debug mode in Visual Studio Code.
After the DevTools extension is installed, when you open an .html file and then click the Inspect button on the Debug toolbar, the Edge DevTools tabs open inside of Visual Studio Code:
In the above screenshot, there's a launch.json file in Explorer in the .vscode folder, and a string from that file, Launch Edge Headless and attach DevTools, at the bottom of the window, because DevTools was opened by a Visual Studio Code feature such as F5, which used the DevTools-generated launch.json file.
In the above screenshot, there's no launch.json file in Explorer in the .vscode folder, and no string such as Launch Edge Headless and attach DevTools at the bottom of the window, because DevTools was opened by right-clicking the .html file in Explorer.
For additional UI steps and screenshots, see Where the name strings appear in the UI. In most cases, the only thing you need to know about the content of the DevTools-generated launch.json file is that you need to enter your desired URL in the "url" string in several places.
Select Generate launch.json to create a launch.json in your project. This must be a longer file that's created by DevTools, as shown in The launch.json file for the DevTools extension, not a short, more generic file created by Visual Studio Code. See also Deleting or re-creating launch.json in Troubleshooting the DevTools extension.
When you choose to debug your project in Visual Studio Code, whether you use DevTools UI features or the usual Visual Studio Code UI features, it will automatically launch the browser and open the Developer Tools, showing the URL you specified in your launch.json file.
Which webpage opens is in DevTools is set by launch.json if that file exists in your workspace (your open folder). Thus you might press F5 while your own .html file is open, and yet see the default, Success page in the DevTools tabs. Options in that case are:
The only issue I still have is I have some JavaScript files with front matter and Liquid and those cause error warnings. Now I tried setting setting the language of all .js files to jekyll too, but that disables JavaScript syntax highlighting. My workaround:
I did all this a while ago and believed this to be correct, so my apologies if there is anything in error. Using these extensions and the JSON file extensions, you should be able to add Shopify/Liquid commands to any html or markdown file without first having to inform VSC you want to use the language.
You mention that you see errors with JS+Liquid. I am not using any of that in my code (it is a purely static site). What I would try is adding another extension to the files.extensions area. I have not tested this, but I recommend you set it up like the following example and give it a try:
d3342ee215