Styling the Personal Tutor Interface with CSS in ASP.NET Core Razor Pages
Styling the Personal Tutor Interface with CSS
Welcome to the final lesson of our "Developing a Personal Tutor Web Application With ASP.NET Core Razor Pages" course! In the previous lesson, you enhanced your personal tutor application by adding query suggestions, making it more user-friendly and efficient for students. Today, we will complete our application by focusing on styling the interface to make it visually appealing and professional. Styling is crucial in educational web applications, as it enhances the learning experience by providing a clean and intuitive interface. We will use CSS to achieve this, ensuring that our tutor application not only functions well but also looks great.
Setting Up the Static Directory in ASP.NET Core Razor Pages
To style our personal tutor interface, we need to create a place for our static files, such as CSS, JavaScript, and images. In ASP.NET Core Razor Pages, static files are typically stored in the wwwroot directory, which is automatically configured to serve static content.
-
Create the Static Directory: In the root of your project, ensure there is a folder named
wwwroot. Insidewwwroot, create a subfolder namedcss. This is where you will store your CSS file. -
How Static Files Are Served: By default, ASP.NET Core serves files from the
wwwrootdirectory. Any file placed inwwwrootcan be accessed by the browser using a path that starts with/, followed by the folder and file name. For example, a CSS file atwwwroot/css/style.cssis accessible at/css/style.css. In Razor Pages, when referencing static files in your HTML (such as in a<link>tag), you should use the~/prefix (e.g.,~/css/style.css) to indicate the web root, which will be correctly resolved at runtime.
No additional code is required to enable static file serving in a standard ASP.NET Core Razor Pages project, as this is handled automatically by the framework.
Linking the CSS File to Your Razor Page
With the static directory set up, the next step is to create a CSS file and link it to your Razor Page.
-
Create the CSS File: In the
wwwroot/cssdirectory, create a file namedstyle.css. This file will contain all the styles for your application. -
Link the CSS File in Your Razor Page: Open your
Tutor.cshtmlfile (or the main Razor Page for your tutor interface) and add a<link>tag within the<head>section to link the CSS file:
The <link> tag uses the ~ (tilde) character to reference the root of the web application, ensuring that the correct path to the CSS file is used. This setup allows your personal tutor interface to be styled effectively using the CSS rules defined in style.css.


