DEV Community

Cover image for I Built a Modern AI Assistant Using HTML, CSS, and JavaScript
Code Hunter Sharath
Code Hunter Sharath

Posted on

I Built a Modern AI Assistant Using HTML, CSS, and JavaScript

AI-powered applications are everywhere, but many tutorials focus only on connecting an API and displaying a response.

I wanted to build something closer to a real-world application.

So I created a modern AI Assistant using vanilla HTML, CSS, and JavaScript with features such as streaming responses, markdown rendering, syntax highlighting, chat history, theme switching, and deployment.

In this article, I'll walk through the architecture, key features, lessons learned, and common mistakes to avoid.

The Final Result

The application includes:

✅ Modern responsive UI

✅ Dark and Light Mode

✅ Streaming AI Responses

✅ Markdown Rendering

✅ Syntax Highlighting

✅ Chat History Persistence

✅ Copy-to-Clipboard Support

✅ Error Handling and Retry Logic

✅ GitHub Pages Deployment

Unlike many beginner projects, this one focuses on both user experience and maintainability.


Why I Built This Project

Many AI chatbot tutorials stop after displaying a response from the API.

However, real applications need much more:

  • Better user experience
  • Error handling
  • State management
  • Responsive design
  • Safe content rendering
  • Persistent conversations

My goal was to build something that developers could use as a portfolio project while learning practical frontend development concepts.


Tech Stack

The project uses:

Frontend

  • HTML5
  • CSS3
  • Vanilla JavaScript

Libraries

  • Marked.js
  • DOMPurify
  • Prism.js

AI Integration

  • Google Generative AI SDK

Deployment

  • GitHub Pages

No frameworks.

No build tools.

Just modern JavaScript.


One Mistake Most AI Tutorials Make

One of the biggest issues I see in AI tutorials is rendering AI-generated content directly into the page.

This can create security risks.

Instead, I used DOMPurify to sanitize AI responses before displaying them.

Example:

const cleanHtml = DOMPurify.sanitize(rawHtml);
Enter fullscreen mode Exit fullscreen mode

A small addition can significantly improve security.


Streaming Responses Improve User Experience

Rather than waiting for the entire response, the application streams content as it is generated.

This creates a smoother and more natural chat experience.

Users receive feedback immediately instead of staring at a loading indicator.


Making Code Responses Look Better

Many AI assistants generate code snippets.

To improve readability, I integrated Prism.js for syntax highlighting and added a custom code block header with:

  • Language labels
  • Copy buttons
  • Better formatting

This dramatically improves the experience for developers using the application.


Chat History Persistence

Users expect conversations to remain available after refreshing the page.

To achieve this, I used localStorage.

Benefits:

  • Faster user experience
  • No backend required
  • Simple implementation

This also makes the project ideal for deployment on GitHub Pages.


Error Handling Matters

Most demos work perfectly during development.

Real applications don't.

I added:

  • Retry Logic
  • API Error Handling
  • User-Friendly Messages
  • Loading States

These features make the application more resilient and production-ready.


Deployment in Minutes

Once the project was complete, deployment was surprisingly simple.

GitHub Pages allowed me to host the entire application for free.

This makes the project accessible to anyone who wants to showcase it in a portfolio or share it publicly.


What I Learned Building This Project

Building an AI application is about much more than calling an API.

The most valuable lessons came from:

  • Handling edge cases
  • Improving UX
  • Managing state
  • Securing AI output
  • Optimizing frontend performance

These areas often have a greater impact on users than the AI model itself.


Full Step-by-Step Video Tutorial

In the complete tutorial, I cover:

  • Gemini API Setup
  • Project Structure
  • UI Design
  • JavaScript Logic
  • Streaming Responses
  • Syntax Highlighting
  • Error Handling
  • Deployment to GitHub Pages

Watch the full build here: 👉 [https://youtu.be/nbFKG_6DkSE]


Final Thoughts

AI projects are a fantastic way to improve frontend development skills because they combine:

  • APIs
  • UI Design
  • State Management
  • User Experience
  • Real-World Problem Solving

If you're building a developer portfolio in 2025, creating projects like this can help you learn practical skills while producing something users genuinely enjoy using.

I'd love to hear what feature you would add next.

Voice Input?

File Uploads?

Memory?

Let me know in the comments.

Top comments (0)