2. New to HTML and CSS? Start Here
MVC views are written in HTML and styled with CSS, with Razor adding C# on top. If you have never written HTML or CSS, learn them first: it will make every later topic much easier. In short, HTML describes what is on a page (headings, text, links, forms) and CSS describes how it looks (colours, spacing, layout). Razor does not replace them. It simply lets you insert C# values into the HTML. The tutorials linked below teach HTML and CSS from zero and include a live editor, so you can type code and see the page appear straight away.
Key points
- HTML = the structure and content of a page.
- CSS = the colours, fonts, spacing and layout.
- Razor = HTML with C# mixed in using the @ symbol.
- Your CSS files go in wwwroot/css and are linked from _Layout.cshtml.
- The tutorial has 12 short lessons ending with a mini project.
Example: HTML, CSS and Razor in one view
@model string
<style>
.banner { background: black; color: white; padding: 16px; }
.mvc-callout { border: 2px solid #000; border-radius: 4px; padding: 16px 18px; margin: 28px 0 8px; background: #f2f2f2; }
.mvc-callout p { margin: 0 0 12px; color: #000; }
</style>
<div class="banner">
<h1>Hello, @Model</h1>
</div>
<p>This line is plain HTML.</p>
Show explanation
The div, h1 and p tags are HTML. The style block is CSS and colours the banner. @Model is Razor and inserts a C# value into the HTML. If the controller passes "Thabo", the page shows Hello, Thabo.
Example: A tiny HTML and CSS page
<h1>My page</h1>
<p>Welcome to my site.</p>
<style>
h1 { color: black; border-bottom: 3px solid black; }
</style>
Show explanation
This is everything a basic page needs. Open the HTML and CSS tutorials to edit it and run it in the browser.
Never written HTML or CSS? Do the beginner tutorials first. They include a live editor where you type code and see the result.
Open the HTML and CSS tutorials