Skip to content

PHP Tutorial Getting Started with PHP

PHP vs HTML, CSS and JavaScript

Lesson 3 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

A website is built from four different tools. Each one has its own job.

ToolWhat it doesWhere it runs
HTMLDescribes the structure and content of a pageBrowser
CSSDescribes how the page looksBrowser
JavaScriptMakes the page react to the userBrowser (mostly)
PHPBuilds the page, handles data, talks to the databaseServer

An example with all four

Imagine a page that lists blog posts.

  • PHP reads the posts from the database and writes the HTML for each one.
  • HTML is the result: headings, paragraphs and links.
  • CSS styles those headings and paragraphs.
  • JavaScript adds a “load more” button that asks the server for the next posts.
index.php
PHP
<?php
$posts = ["Learning PHP", "Understanding forms", "Using sessions"];

foreach ($posts as $post) {
    echo "<article><h2>$post</h2></article>\n";
}
Output
OUTPUT
<article><h2>Learning PHP</h2></article>
<article><h2>Understanding forms</h2></article>
<article><h2>Using sessions</h2></article>

The browser gets only this HTML. It does not know that PHP made it.

The simple rule

Ask one question: does this need to happen on the server or in the browser?

  • Reading from a database, checking a password or saving a file must happen on the server, so use PHP.
  • Opening a menu, validating a field while the user types or animating something must happen in the browser, so use JavaScript and CSS.

Real projects use both. A form can be checked by JavaScript for a fast message and checked again by PHP, because the browser check can always be bypassed. You will see why in PHP Security.

If you are new to the front-end parts, the HTML course, the CSS course and the JavaScript course are on this site.

warning
PHP cannot respond to a click
Once the page is in the browser, PHP is finished. A click can send a new request to the server, which runs PHP again, but PHP itself does not wait inside the page.