Module should not use <blockquote> for captions; use <div> and provide default .image-field-caption CSS

Created on 11 April 2013, over 12 years ago
Updated 6 September 2025, 9 days ago

I love this module! Thank you for creating it. Great job.
There is only one thing that I don't like, that is the large quotation marks at the front of the caption text (see below in picture).

All I want is text to describe the picture, no quotation marks.
So I decided to see if I could get rid of those quotation marks. After doing some searching, I found a solution.

For anyone else who also might want to get rid of those quotation marks, here is how to do it.

In the files section of your website go into the sites/all/modules/image_field_caption folder. In it you will find the image_field_caption.tpl.php file.

The file contains this code:

<?php
/**
 * $image - contains the image html rendered by Drupal
 * $caption - contains the image field caption string
 */
?>
<?php print $image; ?>
<blockquote class="image_field_caption">
  <?php print $caption; ?>
</blockquote>

Open the file in an editor. (I just did it inside of CPanel)
Below are the bottom three lines. On the top and bottom line (of these three lines) change the "blockquote" to "p" so that it looks like this:

<p class="image_field_caption">
  <?php print $caption; ?>
</p>

Then save the file and you are done. Here is what the finished caption looks like:

Thanks for making a great module!
Best wishes,
Stephen

πŸ“Œ Task
Status

Needs review

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Stephen Winters

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    The template uses a <blockquote> element which inherits site-wide blockquote styles and often results in inappropriate formatting for captions as already demonstrated in this issue.

    Most themes style blockquotes for quotations, not captions.

    I will propose to replace <blockquote> with a <div> and add a default CSS style for the .image-field-caption class to provide a clean, neutral caption appearance out of the box.

    This will prevent conflicts with custom blockquote styles and make the module’s output more predictable and easier to theme.

    I will suggest the following style for the class:

    .image-field-caption {
        display: block;
        width: fit-content;    
        margin: .5rem 0;
        font-size: .95rem;
        color: #6b7280;
        background: #f8fafc;
        border-radius: 6px;
        padding: .5em;
        font-style: italic;
        box-shadow: 0 1px 4px rgba(0,0,0,.03);
    }
    
    .image-field-caption p:last-child {
      margin: 0;
    }

    If okay I can submit a merge request with the changes.

  • Thank you for reviving this discussion and for preparing a concrete proposal.

    I believe the original maintainer's approach is still valid today: the module should provide only the minimal markup needed, leaving it up to site builders and themers to override the template in their own theme. With Twig it is straightforward to copy the template and replace <blockquote> with <div> (or any other element) if a project requires it.

    Introducing predefined colors, shadows, and other opinionated styles into the module would reduce flexibility and could conflict with existing design systems. Since there is no truly universal look for captions, it seems better to keep the module neutral and let themes handle presentation.

    If someone wants custom styling, it's also easy to attach it directly in the template with their own library, for example:
    {{ attach_library('your_theme/your_image_caption_styles') }}
    This way both the markup and the styles can be overridden cleanly and in one place.

    @foxy-vikvik what do you think about this?

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    Thanks @kksandr for the response.

    I think that making the module render captions as quotes is not 'minimal markup' because most themes will already have styling for blockquote and for someone to customize the captions, he will first have to get rid of the blockquote styles before adding any custom styles. To get rid of the blockquote styles he will have to override the template. This is making the module developer-centric. An average site builder will not find it fun having to copy over template files for every module he installs.

    On the other hand, if you make it a div, it will be bare and unobstructive and will allow anyone to now cleanly write styles for the caption as they want (that is in the case there is no default custom styling as I proposed).

    The custom style I proposed will fit for most people and if they desire they can override the styles in their custom CSS files, without having to copy template files over.

    If you weigh it on a scale, a div is a more 'minimal markup' than a blockquote.

  • Thanks for raising this point. We discussed it with @foxy-vikvik and decided to add a new markup option, but instead of a styled <div> it will be implemented using <figure> and <figcaption>. Please see πŸ“Œ Create accessible formatter using and tags for captions (a11y compliance) Active for details.

    I will start working on this now. This approach is semantically correct, meets accessibility requirements, and is already used in Drupal core by CKEditor5.

  • Now that this issue is closed, please review the contribution record.

    As a contributor, attribute any organization helped you, or if you volunteered your own time.

    Maintainers, please credit people who helped resolve this issue.

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    Thanks @kksandr

    I did think of <figcaption> as the most semantically correct HTML5 approach but kind of hesitated to mention it as it will involve more work. Good to know you are ready to work on it.

Production build 0.71.5 2024