Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline Custom CSS Fonts In HTML5

Tags:

html

css

fonts

I am trying to use a custom font in a webpage. I however know next to nothing about HTML5 and CSS. I want 1 h1 tag to have a custom font. I have the .ttf file in the same folder as the webpage. I tried this with no success:

<h1 style="text-align: center"; font-family="MinecrafterReg.ttf">Welcome to Ben's Minecraft</h1>

Could anyone else help me?

like image 605
Ben Ackerley Avatar asked Sep 08 '15 16:09

Ben Ackerley


2 Answers

Stick this in the style tags:

@font-face {
font-family: MinecrafterReg;
src: url(MinecrafterReg.ttf);
font-weight:400;

Then stick this in the h1 tag:

<h1 style="text-align: center; font-family: MinecrafterReg">Welcome to Ben's Minecraft</h1>
like image 162
Ben Ackerley Avatar answered Oct 20 '22 01:10

Ben Ackerley


Nowadays you can place an @import at the top of your style block:

<style>
  @import url('https://fonts.googleapis.com/css?family=Roboto');
</style>
like image 31
James Gentes Avatar answered Oct 20 '22 01:10

James Gentes