The Tailwind Typography plugin simply maintains the default font size of heading tags without altering their style

I've been working on parsing an MDX file and converting it into React components.

My tech stack includes TailwindCSS, Next.js, and React. Following the Tailwind documentation, I have installed the tailwind/typography plugin.

In my tailwind.config.js file:

plugins: [require('@tailwindcss/typography'), require('@tailwindcss/aspect-ratio'), require('tailwindcss-textshadow')]

Within the globals.css file:

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
    h1 {
        @apply mb-6 text-3xl font-semibold;
    }
    h2 {
        @apply text-2xl font-semibold;
    }
    p {
        @apply mb-4;
    }
    a {
        @apply text-blue-500 hover:text-blue-400 dark:text-blue-400 dark:hover:text-blue-300;
    }

Then, in my Blog function, I utilize MDXRemote to render HTML elements.

export const Blog = ({ source, frontMatter }: BlogInput) => {
    return (
            <article className="prose">
                <h2>This should have H2 heading style!</h2>
                <div className={s.title}>{frontMatter.title}</div>
                <div>{format(parseISO(frontMatter.date!), 'MMMM dd, yyyy')}</div>
                <div className="">
                    <MDXRemote {...source} components={components} />
                </div>
            </article>
    )
}

This is an example of my MDX file content:

---
title: Example Post
description: '',
date: '2022-01-30'
image: '/images/hello.jpg'
---

# Heading

### This is an example blog post with React components.

However, when rendered, the custom h1/h2 heading styles are not applied, and instead, it displays as static 16px text (which appears to be the default font style for Tailwind).

https://i.sstatic.net/CEi3x.jpg

Interestingly, when checking the font via the VSCode Preview extension, the font style has visibly changed: https://i.sstatic.net/70gfr.png

Is there something crucial that I might be overlooking in this setup?

Answer №1

To enhance the design of your website, integrate these CSS lines and customize them to suit your preferences:

h1 {
    @apply text-3xl;
}
h2 {
    @apply text-2xl;
}
h3 {
    @apply text-xl;
}
a {
    @apply text-blue-600 underline;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to position one div next to another using CSS and HTML

Hey there, I'm facing an issue with creating a sidenav next to a div containing paragraphs and images. I can't seem to make both the sidenav and the other div appear inline. If anyone has any insights on how to solve this problem or spot what I&a ...

dynamic webpage resizing using html and css

Looking for a way to make my SharePoint window automatically resize when the user changes their browser size. I'm using the web version of SharePoint at work and don't have access to Designer. <style type="text/css"> #dgwrap { HEIGHT: ...

What is the best way to incorporate a splatter image within an MDX blog post?

I am working on an MDX blog where I render a blog post. pages/index.tsx <main className="flex min-h-screen dark:bg-black"> <div className="wrapper mb-24 gap-8 px-8 lg:grid lg:grid-cols-[1fr,70px,min(70ch,calc(100%-64 ...

What are the best practices for handling local storage data in a Next.js project when transitioning between user profiles?

I am currently working on a React/Nextjs application where I have implemented a custom useLocalStorage hook to manage local storage for user profiles, simulating a chatgpt app. However, I have encountered an issue where the data in local storage for a new ...

Error: Unable to locate module with associated type definitions when utilizing Typescript in Next.js

Currently, I am working on a next.js project that I'm attempting to integrate typescript into. The structure of my folders is organized as follows: api aggregation.ts interfaces index.ts components Component1 index.js index.module.css ...

Achieve perfect alignment of an HTML table by positioning it precisely 36 pixels away from the right edge of the window

I'm struggling to achieve a table that is precisely 36px away from both the left and right edges of the browser window, regardless of CSS. While I can easily set the left margin, getting the exact right margin seems impossible as the `margin-right` CS ...

How can you toggle the visibility of a div based on detecting a specific class while scrolling?

My webpage features a sticky header that gains an extra .header-scrolled class when users scroll down. I am looking to switch the logo displayed in the header once it has been scrolled. Below is a simplified version of my HTML code: <header class=".he ...

Managing the closest element depending on the selected option in Angular 5

My task involves accessing the nearest element of a dropdown. The HTML below includes multiple dropdowns and input boxes. When selecting options from the dropdown, I need to enable or disable the input box closest to it. <div class="form-block" *ngFor= ...

How to display an object in JS format using React?

Currently, I am tackling a project that presents me with the following situation: myjson: { completeName: "my name is {this.state.myName+ " "+this.state.surname}" } component.js var Component = React.createClass({ getInitialState: function() { ...

Ways to apply styles to the final element containing a specific class within a nested list using CSS

Styling the final HTML element with a specific css class presents challenges due to certain constraints that must be considered. In the website I'm currently working on, the navigation menu consists of multiple nested lists. When an element is clicke ...

What is the best way to implement a secondary sticky navbar that appears on scroll of a specific section, positioned below the primary fixed-top navbar, using jQuery and Bootstrap 5?

I am facing a challenge with my webpage layout. I have a fixed-top navbar at the top, followed by 3 sections. The second section contains nav-tabs. What I want is for the nav-tabs navbar to stick to the top of the page below the fixed-top navbar when the u ...

Customizing CSS by replacing link file styles with code in the HEAD section

UPDATE: After further examination, it appears that the code is functioning correctly. My apologies for any confusion. I am attempting to override certain CSS rules on specific pages. Below is an example of my approach. Can anyone confirm if this is a vali ...

Attempting to transform a numerical value into CSS syntax

Currently, I am attempting to loop through several DIV elements, extract a numerical value from each DIV, and then based on that value matching a specific value in the JavaScript code, assign a particular CSS Class back to the original DIV. This is the sn ...

Ways to adjust the border color when error helper text is displayed on a TextField

I am currently working with React Material UI's TextField element. What I aim to achieve is when the submit button is pressed, the helpertext displayed should be "Please enter the password." It should look like this: However, once the helpertext is ...

"A lengthy contenteditable div designed to mimic an input field, with the ability to horizontally scroll

When the input is too short for the entire text to be displayed, users have the option to horizontally scroll the text inside the input by dragging with the mouse. Is there a way to implement this functionality in a contenteditable field that appears as ...

Unable to locate React.js refs within object

import { Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap'; export default class UserPicForm extends React.Component { constructor() { super(); // establish bindings this.handleSubmission = this.handleSubmission ...

Personalize the arrangement of the list

I'm currently working with the rest-admin Framework and I am looking to make some layout changes to the lists while adding a custom component. At the moment, the layout looks like this: https://i.sstatic.net/ELp9D.png What I aim to do is include a ...

The Bootstrap carousel's transition effect is not functioning as expected

The fade transition I added to my Bootstrap 4 carousel isn't working properly. It seems like the effect is not being applied to the carousel. Here is the HTML code snippet: <div id="testimonialsSlides" class="carousel carousel-fade" data-ride="fa ...

It looks like the title is not defined in the react-chart component

I'm currently working on a COVID-19 tracker, but I'm encountering an issue where the title appears as undefined when the data is displayed on the graph using React charts. Here is the code for my chart: <div > {data?.length > 0 & ...

Is there a way to raise an error in React Native and make it visible?

I am working on a functional component where I need to call a method from another .js file. The method in the external file intentionally throws an error for testing purposes, but I want to propagate this error up to the functional component's method. ...