A tutorial on the difference between HTML and PHP

In this guide, I’ll explain the difference between HTML and PHP, broken down so even beginner coders will understand. Read on to learn more!

What is HTML?

Hypertext Markup Language, or HTML, is one of two main programming language used to create webpages.

Actually, HTML is used to create HTML documents, which can be read by a web-browser (what you’re using to read this article) and displayed as a webpage.

There’s another programming language, called Cascading Style Sheets, or CSS, that is used in conjunction with HTML to change the look and feel of a webpage.

If you’re eager to learn HTML, check out my Beginner’s Guide to Hypertext Markup Language (Updated for 2020).

Confused? I hear you.

Let’s imagine for a moment that we’re building a house.

A foundation is first laid, along with the scaffold for the house, or the framework. Basically, an empty shell.

Once that’s erected, all of the drywall is applied.

Finally, we have to paint and decorate the drywall.

Ok, I’ll admit that was a super simplification of the house building process. But I’m not in construction, and I’m trying to illustrate a point here!


A photo of a man infront of a monitor, learning the difference between HTML and PHP

The framework and scaffold would be HTML code.

The paint and decorations would be the CSS code.

HTML is written using tags of specific keywords. I’m a very visual learner, and so I need to see something to believe it.

Let’s take a look at some sample HTML code:

<div class="container"> <div class="row"> <div class="col-12"> <h1 class="header-text">Hello, I'm a header!</h1> </div> </div> </div>

What do you notice about the code above?

There’s a lot of repeating bracket things, right? Those are the starting and ending tags.

As a result, we get a bunch of those tags inside our HTML documents.

So, now you have a taste of what HTML is, let’s explore what PHP is.

What is PHP?

PHP is a programming language that is processed on a web server, not a web browser like HTML, and is used to create dynamic webpages.

What do I mean when I say dyanmic webpages?

Webpages that change what they display to the end-user are dynamic. For example, after a user signs in to Facebook, they see a personalized feed of content from their connections.

Alternatively, HTML by itself would not be able to display that kind of content as it is only used to create static webpages.

A photo of a laptop with some code on it

WordPress uses PHP heavily.

So how does PHP create dynamic webpages?

PHP acts as the glue between a database and a static webpage built in HTML. In fact, you write PHP inside of HTML code.

As before, let’s take a look at what PHP code looks like:

<?php get_header(); $comments = get_comments_number(); $post_tags = get_the_tags(); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <main role="main" class="pt-5"> <article> <section class="jumbotron post-hero-banner text-center"> <aside class="container container-small"> <h1 class="jumbotron-heading"><?php the_title() ?></h1> <time datetime="<?php echo get_the_date( 'c' ); ?>"> <?php the_date() ?> </time> / <a href="#comments"><?php echo ($comments == 0) ? "Leave a comment" : $comments . " comment" . ($comments > 1 ? 's' : null) ?></a> <div class="category-tags"> <?php if ($post_tags) { foreach(get_the_tags($post->ID) as $tag) { if ($tag->name !== react) { echo '<span class="category-tag"><a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a></span>'; } } } ?> </div> </aside> </section>

A LOT different than static HTML, right?

Well, kinda.

There’s still static HTML nestled inside of the PHP, or rather PHP code nestled inside of the HTML tags.

Either way, that’s what PHP code looks like.

So, What’s the Difference Between HTML and PHP?

Rather than write a boring list of containing the difference between HTML and PHP, I’ll make the comparison using common website scenarios.

Read these scenarios to learn the difference between HTML and PHP:

  • I Want to Create a Blog
  • Create a Simple, No-thrills Webpage
  • I Want My Web-page to Display Data from a Database

The main difference between HTML and PHP is that HTML is used to create static web-pages.

Whereas PHP is used to connect to a database and turn those static HTML web-pages into dynamic pages.

I Want to Create a Blog

If it’s a blog that you want, then WordPress is your go to platform and content management system (CMS).

WordPress relies on PHP heavily. In fact, it was first created using PHP.

To this day, PHP powers the back end of WordPress even though they recently upgraded the editor to use React and JavaScript.

Create a Simple, No-thrills Webpage

If it’s simplicity that you’re after, then plain old static HTML is what you’re after. HTML and CSS can get you pretty far when creating a webpage.

Static HTML is much, much quicker than a PHP backed webpage as there s no delay in connecting to a database, unlike WordPress, for example.

That’s why there is a new wave of blogs being built entirely using something called the JAM stack (JavaScript, API, and Markup).

It’s database-less and PHP-less. Therefore it’s really, really fast at rendering pages. Google’s PageSpeed Insights absolutely loves blogs and website built on the JAM stack.

There’s a framework out called Gatsby (no, not the 1920s millionaire socialite!) that makes it easy to build a static webpage generator using React.

Check it out.

I Want My Web-page to Display Data From a Database

Again, if it’s a dynamic web-page you’re after, then PHP is your go to programming language.

Although you’ll need to also write HTML in order to display the database data appropriately on the web-page!

You can use PHP to make a connection to a database where a user’s data is stored, for example.

Then, you can output that specific data to a webpage.

A user can browse to the same page and see different data because they are different users and therefore different data is stored about them in the database.

🚀 Follow My Journey from 0 to 100,000 Monthly Pageviews!

Starting with this brand-new blog, I'm sharing everything I do to get from 0 pageviews to 100,000 monthly pageviews, every step of the way.
Zero spam, just great content. Unsubscribe at any time.

💬 Leave a comment

Your email address will not be published. Required fields are marked *

We will never share your email with anyone else.