Getting Started with Visual Studio Code and Building HTML Websites

In this article, we will go over the steps necessary to download a popular text editor called Visual Studio Code, also referred to as “VS Code.” By the end of the article you will be able to create a folder in Visual Studio Code that contains an HTML document that you can open in your web browser.

I. Introduction

What are ‘text editors’.

Text editors, also called code editors, are applications used by developers to write code. They can highlight and format your code so that it’s easier to read and understand. If you’ve used Codecademy, you’re already familiar with a text editor. It’s the area you write your code in.

Using a text editor is part of creating your “development environment,” the set of tools that you use for working on coding projects. It will allow you to take what you’ve learned on Codecademy and put it into practice as you work on projects on your computer. Not only will this introduce you to tools that are commonly used by professional developers but it also means that you’ve grown as a developer and are ready to start working on your own—great work!

Specific to writing code, text editors provide a number of advantages:

You may also have read or heard about IDEs, or “integrated development editors.” An IDE allows you to not only edit, but also compile, and debug your code through one application or interface. While the text editor we recommend isn’t considered an IDE, it has many IDE-like features that make life as a developer easier without needing a lot of resources that an IDE usually requires. The best of both worlds!

Choosing a Text Editor

There are a number of text editors to choose from. For example, Visual Studio Code is one of the most popular text editors used by developers. (That’s Visual Studio Code and not Visual Studio, which is slightly different. We want the former, the one with ‘Code’ in the name.) Other popular text editors you may have heard of are Atom and Sublime Text.

Any of these text editors mentioned are great for development but to make things easier, we suggest you start off with Visual Studio Code. Some of the benefits of this editor are:

When you are further along in your coding career, you can try other code editors to see what features work best with your personal development workflow.

II. Installing Visual Studio Code

So, we’ve chosen our text editor, now we just need to install it on our computer!

Video Instructions

For the visual learners, this video details how to download and install Visual Studio Code. Written instructions are below.

Installation Steps

The installation process for computers running macOS, Windows, and Linux, (specifically Ubuntu and Debian), will be very similar and using Visual Studio Code across all of them will be the same.

Visit the Visual Studio Code website to download the latest version of Visual Studio Code.

how to write html code in visual studio

You should see your computer’s operating system displayed, but if it’s not correct, click on the down arrow and find the option that matches your operating system from the drop down menu and click on the down arrow icon under “Stable.”

Windows users: This will download the latest version of Visual Studio Code as an .exe file.

Mac users: This will download the latest version of Visual Studio Code for Mac as a .zip file.

Linux users: .deb and .rpm are different file types for storing data. We suggest you download the .deb file so auto-updates work as the Visual Studio Code documentation suggests.

Once the Visual Studio Code file is finished downloading, we need to install it. Find the Visual Studio Code file in your file manager, the program that lets you see the files and folders on your computer.

Windows users: Open the .exe file by clicking on it and on run the installer. Keep clicking ‘Next’ and then finally ‘Finish.’

Mac users: The downloaded .zip file should be in your ‘Downloads’ folder. Open the file. If you see this message choose “Open.”

Linux users: The downloaded file should be in your ‘Downloads’ folder.

Find it in your file manager, double click and choose ‘Install’ in the GUI software center, or run the following commands, one at a time, in the terminal:

Make sure you have your Visual Studio Code application saved in a place you know you will easily be able to find it.

Windows users: It will automatically be placed in your Start menu.

Mac users: Click and drag the Visual Studio Code icon from the Downloads folder to the Applications folder.

Linux users: It should appear in your task bar of programs.

That’s it, you’ve successfully installed your text editor and are ready to start coding!

III. Practice: Use Visual Studio Code to start an off platform project

As you move through various lessons and paths here on Codecademy, you may find yourself needing to create a project on your own computer and not on the Codecademy learning environment. This can be tricky, but it’s an exciting step that signals that you are ready to work independently.

To do this, we’ll need to use the text editor we installed above. Let’s take a moment to try out Visual Studio Code.

What are ‘development folders’?

Before using your text editor, it’s important to establish an organized file system. As the number and size of your projects grow, it becomes increasingly important to know where to save new projects and find old projects.

Most developers store their projects in an easy-to-find directory, (what you might be used to calling a ‘folder’). Here at Codecademy, we recommend naming this directory projects . It will store all of your coding projects. Whenever you create a new project, no matter how small, you should always make a new folder inside your projects directory. You will find that single-file projects can quickly turn into large, multi-folder projects.

Practice: Let’s make a project

Below are the steps you need to follow to create a new folder for all of your programming projects. You will also learn how to load a new project folder into Visual Studio Code and make your very first “hello world” HTML project.

We’d recommend that you watch the above video and then follow the written steps below.

1. Make a development folder.

Navigate to a folder using your file manager or the terminal. Make sure it is a folder you visit regularly and will remember. Create a new folder called projects .

Mac users: This may be your User account or “Home” folder.

Windows users: You may want to save this on your C drive.

Linux users: You may want to save this in your User folder inside of the “Home” folder.

Inside the projects folder, create a new folder called HelloWorld . Everything you add to this folder will be part of your HelloWorld project.

2. Open Visual Studio Code

3. open your development folder.

Click on the ‘Explorer’ icon on the left hand menu and click on the button ‘Open Folder’ and choose your development folder. This will launch your file manager.

Navigate to the HelloWorld folder and select Open. The folder will open in Visual Studio Code’s side pane. At this point, there should not be any contents in the folder. We’ll add a file in the next step.

4. Add a file.

Before you learn how to add files to a project folder, it is important to understand the purpose of file extensions. A file extension is the suffix of a filename (the last 3 or 4 characters in a filename, preceded by a period) and describes the type of content the file contains. For example, the HTML file extension is .html, and it tells the browser (and other applications) to interpret the contents of the file as an HTML document. Once Visual Studio Code loads a project folder, you can add files. The steps below describe how to add files. Don’t worry about doing this on your own computer. We’ll get to that next.

In Visual Studio Code’s Explorer pane, click on your development folder’s name. You’ll see four icons appear to the right of the folder name. Click the ’New File’ icon. Type the new file’s name with its appropriate file extension ( for example, .html, .css, .csv). It is critical that you include the correct file extension, so programs like linters know how to interpret its contents. Press Enter when done.

5. Begin coding!

Copy and paste the following boilerplate HTML code:

Save your file often with the Auto Save feature and track changes with a version control system if you know how to use one. (To turn Auto Save on, click on ‘File’ then ‘Auto Save’. When it’s on, you’ll see a check mark next to ‘Auto Save’.) This will decrease the chances of losing unsaved work.

File Extensions and Syntax Highlighting

Syntax is the set of rules that tell us how to create correctly written code. Visual Studio Code and other text editors are able to interpret file extensions and provide language-specific syntax highlighting. Syntax highlighting is a tool for making code easier to read. Take a look at your index.html file. The text and tags are different colors. This is how Visual Studio Code highlights .html syntax. With each new language you learn, Visual Studio Code will highlight text in a way that makes your code easy to read. This may be different than other text editors and also different than the way your code is highlighted on Codecademy.

Optional: Change the color scheme

Although Visual Studio Code comes with default syntax highlighting, you may want to change the colors used. Good color themes will make reading all those lines of code easy on your eyes. (Try out low contrast, dark themes like “Solarized Dark” or “Dracula Dark.”)

To do this, select Color Theme from the Welcome page when you first open Visual Studio Code, or click on Code in the menu bar at the top of your desktop window, then click on Preferences, followed by Color Theme. You can also search for color themes to install using the Extensions menu .

6. View your HTML file in the browser

At this point, your file is ready to be viewed in a web browser. The following steps should be taken outside of Visual Studio Code:

Navigate to the index.html file in your Hello World folder through your file manager or terminal.

Double click or open index.html . The page should open in your default web browser. Take second to marvel at your handiwork—you made your first project with Visual Studio Code.

Go further with Visual Studio Code’s features

If you already feel comfortable with the previous steps, explore the following features to further customize your development environment. You don’t need to use these suggestions to complete the projects on Codecademy but they can help make you more efficient when writing code and are what make Visual Studio Code such a useful editor!

Debugging code in the editor: That’s right, you can run and test code from the editor!

Version control: You don’t need to switch to the terminal on your computer to track changes with Git.

Integrated terminal: You can run command line commands from your editor with Visual Studio Code.

IV. Wrapping up

Congratulations! You’ve successfully set up your text editor and are ready to create websites on your own computer.

Happy coding!

Learn More on Codecademy

Create a front-end app with react, create an advanced web app with react and redux.

Version 1.76 is now available! Read about the new features and fixes from February.

HTML in Visual Studio Code

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.

IntelliSense

As you type in HTML, we offer suggestions via HTML IntelliSense. In the image below, you can see a suggested HTML element closure </div> as well as a context specific list of suggested elements.

HTML IntelliSense

Document symbols are also available for HTML, allowing you to quickly navigate to DOM nodes by id and class name.

You can also work with embedded CSS and JavaScript. However, note that script and style includes from other files are not followed, the language support only looks at the content of the HTML file.

You can trigger suggestions at any time by pressing ⌃Space (Windows, Linux Ctrl+Space ) .

You can also control which built-in code completion providers are active. Override these in your user or workspace settings if you prefer not to see the corresponding suggestions.

Tag elements are automatically closed when > of the opening tag is typed.

The matching closing tag is inserted when / of the closing tag is entered.

You can turn off autoclosing tags with the following setting :

Auto update tags

When modifying a tag, the linked editing feature automatically updates the matching closing tag. The feature is optional and can be enabled by setting:

Color picker

The VS Code color picker UI is now available in HTML style sections.

color picker in HTML

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.

Move the mouse over HTML tags or embedded styles and JavaScript to get more information on the symbol under the cursor.

HTML Hover

The HTML language support performs validation on all embedded JavaScript and CSS.

You can turn that validation off with the following settings:

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.

Additionally you can use the following region markers to define a folding region: <!-- #region --> and <!-- endregion -->

If you prefer to switch to indentation based folding for HTML use:

To improve the formatting of your HTML source code, you can use the Format Document command ⇧⌥F (Windows Shift+Alt+F , Linux Ctrl+Shift+I ) to format the entire file or Format Selection ⌘K ⌘F (Windows, Linux Ctrl+K Ctrl+F ) to just format the selected text.

The HTML formatter is based on js-beautify . The formatting options offered by that library are surfaced in the VS Code settings :

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.

The Marketplace has several alternative formatters to choose from. If you want to use a different formatter, define "html.format.enable": false in your settings to turn off the built-in formatter.

Emmet snippets

VS Code supports Emmet snippet expansion. Emmet abbreviations are listed along with other suggestions and snippets in the editor auto-completion list.

Tip: See the HTML section of the Emmet cheat sheet for valid abbreviations.

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.

For example, to use Emmet HTML abbreviations inside JavaScript:

We also support User Defined Snippets .

HTML custom data

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.

You can read more about using custom data in the vscode-custom-data repository.

HTML extensions

Install an extension to add more functionality. Go to the Extensions view ( ⇧⌘X (Windows, Linux Ctrl+Shift+X ) ) and type 'html' to see a list of relevant extensions to help with creating and editing HTML.

Tip: Click on an extension tile above to read the description and reviews to decide which extension is best for you. See more in the Marketplace .

Read on to find out about:

Common questions

Does vs code have html preview.

No, VS Code doesn't have built-in support for HTML preview but there are extensions available in the VS Code Marketplace . Open the Extensions view ( ⇧⌘X (Windows, Linux Ctrl+Shift+X ) ) and search on 'live preview' or 'html preview' to see a list of available HTML preview extensions.

How to Run a HTML File in Visual Studio Code

Last Updated: February 13, 2023

This article was written by Stan Kats and by wikiHow staff writer, Travis Boylls . Stan Kats is the COO and Chief Technologist for The STG IT Consulting Group in West Hollywood, California. Stan provides comprehensive technology & cybersecurity solutions to businesses through managed IT services, and for individuals through his consumer service business, Stan's Tech Garage. Stan has over 7 years of cybersecurity experience, holding senior positions in information security at General Motors, AIG, and Aramark over his career. Stan received a BA in International Relations from The University of Southern California. This article has been viewed 168,385 times.

Visual Studio Code is a source code editor made by Microsoft. It is available for Windows, macOS, and Linux. It allows you to write and edit code in a variety of coding languages, including HTML. But what do you do when you want to run your HTML code to see how it looks. Luckily there are a number of extensions for Visual Studio Code that allow you to easily run HTML code from within Visual Studio Code. You can also use the Terminal to run an HTML file. This wikiHow article teaches you how to run an HTML file in Visual Studio Code.

Creating, Opening, and Saving an HTML File

Image titled Run a HTML File in Visual Studio Code Step 1

Image titled Run a HTML File in Visual Studio Code Step 2

Image titled Run a HTML File in Visual Studio Code Step 3

Using the Terminal

Image titled Run a HTML File in Visual Studio Code Step 4

Image titled Run a HTML File in Visual Studio Code Step 7

Image titled Run a HTML File in Visual Studio Code Step 8

Using the "HTML Preview" Extension

Image titled Run a HTML File in Visual Studio Code Step 9

Using the "Open in Browser" Extension

Image titled Run a HTML File in Visual Studio Code Step 16

Expert Q&A

You might also like.

Create a Simple Web Page with HTML

Expert Interview

how to write html code in visual studio

Thanks for reading our article! If you'd like to learn more about Computer Networking, check out our in-depth interview with Stan Kats .

About This Article

Stan Kats

1. Open or create an HTML file in Visual Studio Code. 2. Click the Extensions button on the left side. 3. Search for "HTML Preview" and install it. 4. Click the tab for your HTML file at the top. 5. Click the icon that resembles a split-screen with a magnifying glass at the top. Did this summary help you? Yes No

Is this article up to date?

Am I a Narcissist or an Empath Quiz

Featured Articles

Make Tzatziki

Trending Articles

What's Your Mindset Quiz

Watch Articles

Make Tabasco Sauce

Keep up with tech in just 5 minutes a week!

// Tutorial //

How to set up your html project with vs code.

Default avatar

By Erin Glass

Senior Manager, DevEd

How To Set Up Your HTML Project With VS Code

To explore HTML in practice and begin building an HTML website, we’ll need to set up a new project using a text editor. This tutorial series uses Visual Studio Code , a free code editor available for Mac, Windows, or Linux, but you may use whichever code editor you prefer.

After opening your preferred text editor, open up a new project folder and name it html-practice . We’ll use this folder to store all the files and folders we create in the course of this tutorial series.

To create a new project folder in Visual Studio Code, navigate to the “File” menu item in the top menu and select “Add Folder to Workspace.” In the new window, click the “New Folder” button and create a new folder called html-practice as illustrated in the gif below:

Next, create a new file called index.html inside the html-practice folder. We’ll use this file through the tutorial series to experiment with HTML. If you are using Visual Studio Code, you can create a new file by using Right Click (on Windows) or CTRL + Left Click (on Mac) on the html-practice folder, selecting “New File”, and creating the file index.html as illustrated in the gif below:

You now have a project folder and file for exploring HTML. We’ll return to this file in the tutorials ahead.

Debugging and Troubleshooting CSS and HTML

Before we get started with our HTML exercises, be aware that precision is important when writing HTML. Even an extra space or mistyped character can keep your code from working as expected.

If your HTML code is not rendering in the browser as intended, make sure you have written the code exactly. To troubleshoot errors, check for extra or missing spaces, missing or misspelled tags, and missing or incorrect punctuation or characters. Each time you change your code, make sure to save your file before reloading it in the browser to check your results.

A Quick Note on Automatic HTML Support Features

Some code editors—such as the Visual Studio Code editor that we’re using in this series—provide automatic support for writing HTML code. For Visual Studio Code, that support includes smart suggestions and auto completions . While this support is often useful, be aware that you might generate extra code that will create errors if you’re not used to working with these support features. If you find these features distracting, you can turn them off in the code editor’s preferences.

We are now ready to begin learning how the CSS language works. In the next tutorial, we’ll begin exploring how CSS rules are used to control the style and layout of HTML content on a webpage.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us

Tutorial Series: How To Build a Website with HTML

This tutorial series will guide you through creating and further customizing this website using HTML, the standard markup language used to display documents in a web browser. No prior coding experience is necessary but we recommend you start at the beginning of the series if you wish to recreate the demonstration website.

At the end of this series, you should have a website ready to deploy to the cloud and a basic familiarity with HTML. Knowing how to write HTML will provide a strong foundation for learning additional front-end web development skills, such as CSS and JavaScript.

Open source advocate and lover of education, culture, and community.

Still looking for an answer?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Creative Commons

Popular Topics

Try DigitalOcean for free

Join the tech talk.

Please complete your information!

IMAGES

  1. How to use visual studio code

    how to write html code in visual studio

  2. Visual Studio Code 1 License Key Download FREE

    how to write html code in visual studio

  3. How to run HTML code in Visual Studio Code on Mac OS

    how to write html code in visual studio

  4. Visual Studio Code “Custom Editors”

    how to write html code in visual studio

  5. HTML in Visual Studio Code

    how to write html code in visual studio

  6. Visual Studio Code Webview Example

    how to write html code in visual studio

VIDEO

  1. Writing Basic Html

  2. How To Redirect a Page in PHP In 1 Second

  3. Html in VS code || Vs code tricks || shortcuts of VS code ||

  4. Run HTML code in VS Code

  5. How to write html code

  6. Basic HTML Tutorial 1- VS Code Installation

COMMENTS

  1. Getting Started with Visual Studio Code and Building HTML Websites

    1. Make a development folder. · 2. Open Visual Studio Code · 3. Open your development folder · 4. Add a file. · 5. Begin coding! · 6. View your HTML file in the

  2. HTML Programming with Visual Studio Code

    HTML in Visual Studio Code · "html.suggest.html5" true · "html.autoClosingTags" false · "editor.linkedEditing" true · "html.validate.styles" true

  3. How to create HTML project in Visual Studio 2019

    How to create Html Project in Visual Studio 2019 | Visual Studio community edition 2019 beginners tutorial on how to use visual studio 2019

  4. How to Run HTML in Visual Studio Code on Windows 10 2020

    Run HTML in visual studio code on Windows 10Hey, guys in this video I'm going to show you how you can configure visual studio code (#vscode)

  5. Create a Website with HTML & CSS

    SUPPORT US: https://bit.ly/32UCmzmLearn how to create a simple modern website with HTML5 and CSS using Visual Studio Code editor - Web

  6. How To Create HTML Project In Visual Studio 2022

    How to create html project in visual studio 2022 is a tutorial in HTML suitable for beginners or people who are new to Visual Studio world.

  7. How to Run HTML in Visual Studio Code on Windows 11

    In this Video I am going to show How To Open Browser Or Run Program Directly From Visual Studio Code. In addition I am also going to show

  8. How to Setup Visual Studio Code for HTML, CSS, and JavaScript

    In this video, I will show you how to Setup Visual Studio Code for HTML, JS, and CSS. Enjoy the video! ⏰Timestamps⏰ 00:00 Intro 00:30

  9. 4 Ways to Run a HTML File in Visual Studio Code

    To create a new file, click File in the menu bar at the top. Then click New File. Begin typing your HTML code. To open an existing file, click File in the menu

  10. How To Set Up Your HTML Project With VS Code

    Some code editors—such as the Visual Studio Code editor that we're using in this series—provide automatic support for writing HTML code. For