Managing User Focus with :focus-visible

This is going to be the 2nd post in a small series we are doing on form accessibility. If you missed the first post, check out Accessible Forms with Pseudo Classes. In this post we are going to look at :focus-visible and how to use it in your web sites!

Focus Touchpoint

Before we move forward with :focus-visible, let’s revisit how :focus works in your CSS. Focus is the visual indicator that an element is being interacted with via keyboard, mouse, trackpad, or assistive technology. Certain elements are naturally interactive, like links, buttons, and form elements. We want to make sure that our users know where they are and the interactions they are making.

Remember don’t do this in your CSS!

:focus {
  outline: 0;
}

/*** OR ***/

:focus {
  outline: none;
}

When you remove focus, you remove it for EVERYONE! We want to make sure that we are preserving the focus.

If for any reason you do need to remove the focus, make sure there is also fallback :focus styles for your users. That fallback can match your branding colors, but make sure those colors are also accessible. If marketing, design, or branding doesn’t like the default focus ring styles, then it is time to start having conversations and collaborate with them on the best way of adding it back in.

What is focus-visible?

The pseudo class, :focus-visible, is just like our default :focus pseudo class. It gives the user an indicator that something is being focused on the page. The way you write :focus-visible is cut and dry:

:focus-visible {
  /* ... */
}

When using :focus-visible with a specific element, the syntax looks something like this:

.your-element:focus-visible {
  /*...*/
}

The great thing about using :focus-visible is you can make your element stand out, bright and bold! No need to worry about it showing if the element is clicked/tapped. If you choose not to implement the class, the default will be the user agent focus ring which to some is undesirable.

Backstory of focus-visible

Before we had the :focus-visible, the user agent styling would apply :focus to most elements on the page; buttons, links, etc. It would apply an outline or “focus ring” to the focusable element. This was deemed to be ugly, most didn’t like the default focus ring the browser provided. As a result of the focus ring being unfavorable to look at, most authors removed it… without a fallback. Remember, when you remove :focus, it decreases usability and makes the experience inaccessible for keyboard users.

In the current state of the web, the browser no longer visibly indicates focus around various elements when they have focus. The browser instead uses varying heuristics to determine when it would help the user, providing a focus ring in return. According to Khan Academy, a heuristic is, “a technique that guides an algorithm to find good choices.”

What this means is that the browser can detect whether or not the user is interacting with the experience from a keyboard, mouse, or trackpad and based on that input type, it adds or removes the focus ring. The example in this post highlights the input interaction.

In the early days of :focus-visible we were using a polyfill to handle the focus ring created by Alice Boxhall and Brian Kardell, Mozilla also came out with their own pseudo class, :moz-focusring, before the official specification. If you want to learn more about the early days of the focus-ring, check out A11y Casts with Rob Dodson.

Focus Importance

There are plenty of reasons why focus is important in your application. For one, like I stated above, we as ambassadors of the web have to make sure we are providing the best, accessible experience we can. We don’t want any of our users guessing where they are while they are navigation through the experience.

One example that always comes to mind is the Two Blind Brothers website. If you go to the website and click/tap (this works on mobile), the closed eye in the bottom left corner, you will see the eye open and a simulation begins. Both the brothers, Bradford and Bryan Manning, were diagnosed at a young age with Stargardt’s Disease. Stargardt’s disease is a form of macular degeneration of the eye. Over time both brothers will be completely blind. Visit the site and click the eye to see how they see.

If you were in their shoes and you had to navigate through a page, you would want to make sure you knew exactly where you were throughout the whole experience. A focus ring gives you that power.

Image of the home page from the Two Blind Brothers website.

Demo

The demo below shows how :focus-visible works when added to your CSS. The first part of the video shows the experience when navigating through with a mouse the second shows navigating through with just my keyboard. I recorded myself as well to show that I did switch from using my mouse, to my keyboard.

Video showing how the heuristics of the browser works based on input and triggering the focus visible pseudo class.
Video showing how the heuristics of the browser works based on input and triggering the focus visible pseudo class.

The browser is predicting what to do with the focus ring based on my input (keyboard/mouse), and then adding a focus ring to those elements. In this case, when I am navigating through this example with the keyboard, everything receives focus. When using the mouse, only the input gets focus and the buttons don’t. If you remove :focus-visible, the browser will apply the default focus ring.

The code below is applying :focus-visible to the focusable elements.

:focus-visible {
  outline-color: black;
  font-size: 1.2em;
  font-family: serif;
  font-weight: bold;
}

If you want to specify the label or the button to receive :focus-visible just prepend the class with input or button respectively.

button:focus-visible {
  outline-color: black;
  font-size: 1.2em;
  font-family: serif;
  font-weight: bold;
}

/*** OR ***/

input:focus-visible {
  outline-color: black;
  font-size: 1.2em;
  font-family: serif;
  font-weight: bold;
}

Support

If the browser does not support :focus-visible you can have a fall back in place to handle the interaction. The code below is from the MDN Playground. You can use the @supports at-rule or “feature query” to check support. One thing to keep in mind, the rule should be placed at the top of the code or nested inside another group at-rule.

<button class="button with-fallback" type="button">Button with fallback</button>
<button class="button without-fallback" type="button">Button without fallback</button>
.button {
  margin: 10px;
  border: 2px solid darkgray;
  border-radius: 4px;
}

.button:focus-visible {
  /* Draw the focus when :focus-visible is supported */
  outline: 3px solid deepskyblue;
  outline-offset: 3px;
}

@supports not selector(:focus-visible) {
  .button.with-fallback:focus {
    /* Fallback for browsers without :focus-visible support */
    outline: 3px solid deepskyblue;
    outline-offset: 3px;
  }
}

Further Accessibility Concerns

Accessibility concerns to keep in mind when building out your experience:

  • Make sure the colors you choose for your focus indicator, if at all, are still accessible according to the information documented in the WCAG 2.2 Non-text Contrast (Level AA)
  • Cognitive overload can cause a user distress. Make sure to keep styles on varying interactive elements consistent

Browser Support

This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.

Desktop

ChromeFirefoxIEEdgeSafari
864*No8615.4

Mobile / Tablet

Android ChromeAndroid FirefoxAndroidiOS Safari
12312412315.4

Managing User Focus with :focus-visible originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

How to Add Password to PDF Documents in Google Drive

The Document Studio add-on helps you create personalized PDF documents from Google Sheets. You can generate invoices, certificates, agreements, offer letters, student ID cards and other documents in bulk and save them to Google Drive.

Additionally, Document Studio now offers the option to protect the generated PDF documents with a password.

This functionality is particularly valuable in scenarios where the generated documents contain sensitive information that require extra protection to stop unauthorized access. For instance, you may generate invoices, or financial reports and protect them with a password before sharing them with clients or employees.

Add Passwords to PDF Documents

Let’s walk through the steps of adding passwords to PDF documents generated from Google Sheets using Document Studio.

Prepare Salary Data in Google Sheets

Employee Salary Slips in Google Sheets

We have a Google Sheet that contains the employee’s name, and the salary amount. We’ll use Document Studio to generate individual PDF salary slips for each employee and then add a password to each PDF document before saving them to Google Drive.

Create Template in Google Docs

We have created a salary slip template in Google Docs that contains placeholders for the employee’s name and the salary amount. The data from Google Sheet will be merged into this template to generate individual PDF documents for each employee.

Google Docs - Salary Template

Password Protect PDF Documents

Launch Document Studio in Google Sheets and create a new workflow. If you are new here, please refer to the step-by-step guide or watch this video tutorial to get started.

Inside the workflow, choose the Google Sheet that contains the employee data and the Google Docs template that you have prepared for the salary slips. Next, select the folder in Google Drive where the generated PDF documents will be saved.

Set the export format to PDF and enable the Password Protect PDF checkbox.

Create Password Protected PDF Documents

Unique Password for Each PDF Document

You can choose to use a common password for all the PDF documents or, for added security, set a unique password for each document. For this example, we’ll define a unique password for each PDF document using the employee ID and the first four letters of the employee’s name, all in uppercase.

For instance, if the employee ID is E345 and the employee’s name is Angus, the password for the corresponding PDF document will be E345ANGU.

We’ll make use of Scriptlets to derive a unique password for each PDF document dynamically.

{{ Employee ID }}{? "{{ Employee Name }}" | slice: 0,4 | upcase ?}

The scriptlet above concatenates the employee ID with the first four characters of the employee’s name, converted to uppercase.

Generate PDF Documents

Save the workflow and run it to generate the PDF salary slips for all employees. The generated PDF documents will be saved to the specified Google Drive folder and each document will be protected with a unique password.

Also see: Remove PDF Password from Gmail Attachments

Video is not the main content of the page

Hello everyone, i am not able to fix this issue in the Search Console Video is not the main content of the page but actually it is!

When you enter in my product page the first thing that appears is the video it self! (hosted on imgur platform)

I even added additional Schema video tags but that seems is useless.

here is the code i am using:

P.S: $image4 variable sometimes can contain video link or image link.

<?php if (!empty($image4)): ?>
    <div class="swiper-slide">
        <div class="dz-media" itemscope itemtype="http://schema.org/VideoObject">
            <?php
            if (pathinfo($image4, PATHINFO_EXTENSION) === 'mp4') {
                // Display a video if the link points to an MP4 file
                echo '<meta itemprop="thumbnailUrl" content="' . $image1 . '">';
                echo '<meta itemprop="contentUrl" content="' . $image4 . '">';
                echo '<video controls width="100%" height="auto" poster="' . $image1 . '" itemprop="video">';
                echo '<source src="' . $image4 . '" type="video/mp4">';
                echo 'Your browser does not support the video tag.';
                echo '</video>';
            } elseif (in_array(pathinfo($image4, PATHINFO_EXTENSION), array('png', 'jpg', 'jpeg'))) {
                // Display an image if the link points to a PNG, JPG, or JPEG file
                echo '<img src="' . $image4 . '" alt="' . $product_tags . '">';
            }
            ?>
            <meta itemprop="name" content="<?php echo htmlspecialchars($product_name); ?>">
            <meta itemprop="description" content="<?php echo htmlspecialchars($product_description); ?>">
            <meta itemprop="uploadDate" content="<?php echo date('c', strtotime($upload_date)); ?>">
        </div>
    </div>
<?php endif; ?>

please anyone with the knowledge how to fix this problem

here is a link to a product page on my website
https://www.kupisi.mk/product/-/---/48

@Dani please remove the backlinks if possible, so my site doesn't get indexed :D

The Things Users Would Appreciate In Mobile Apps

Remember the “mobile first” mantra? The idea was born out of the early days of responsive web design. Rather than design and build for the “desktop” up front, a “mobile-first” approach treats small screens as first-class citizens. There’s a reduced amount of real estate, certainly less than the number of pixels we get from the viewport of Firefox expanded fullscreen on a 27-inch studio monitor.

The constraint is a challenge to make sure that whatever is sent to mobile devices is directly relevant to what users should need; nothing more, nothing less. Anything more additive to the UI can be reserved for wider screens where we’re allowed to stretch out and make more liberal use of space.

/* A sample CSS snippet for a responsive main content */

/* Base Styles */
.main-content {
  container: main / inline-size;
}

.gallery {
  display: grid;
  gap: 1rem;
}

/* Container is wider than or equal to 700px */
@container main (width >= 700px) {
  .gallery {
    grid-template-columns: 1fr 1fr;
  }
}

/* Container is wider than or equal to 1200px */
@container main (width >= 1200px) {
  .gallery {
    grid-template-columns: repeat(4, 1fr);
  }
}

Now, I’m not here to admonish anyone who isn’t using a mobile-first approach when designing and building web interfaces. If anything, the last five or so years have shown us just how unpredictable of a medium the web is, including what sort of device is displaying our work all the way down to a user’s individual preferences.

Even so, there are things that any designer and developer should consider when working with mobile interfaces. Now that we’re nearly 15 years into responsive web design as a practice and craft, users are beginning to form opinions about what to expect when trying to do certain things in a mobile interface. I know that I have expectations. I am sure you have them as well.

I’ve been keeping track of the mobile interfaces I use and have started finding common patterns that feel mobile in nature but are more desktop-focused in practice. While keeping track of the mobile interfaces I use, I’ve found common patterns that are unsuitable for small screens and thus could use some updates. Here are some reworked features that are worth considering for mobile interfaces.

Economically-Sized Forms

There are myriad problems that come up while completing mobile forms — e.g., small tap targets, lack of offline support, and incorrect virtual keyboards, to name a few — but it’s how a mobile form interacts with the device’s virtual keyboard that draws my ire the most.

The keyboard obscures the form more times than not. You tap a form field, and the keyboard slides up, and — poof! — it’s as though half the form is chopped out of view. If you’re thinking, Meh, all that means is a little extra scrolling, consider that scrolling isn’t always a choice. If the page is a short one with only the form on it, it’s highly possible what you see on the screen is what you get.

A more delightful user experience for mobile forms is to take a “less is more” approach. Display one form field at a time for an economical layout that allows the field and virtual keyboard to co-exist in harmony without any visual obstructions. Focusing the design on the top half of the viewport with room for navigation controls and microcopy creates a seamless flow from one form input to the next.

More Room For Searching

Search presents a dichotomy: It is incredibly useful, yet is treated as an afterthought, likely tucked in the upper-right corner of a global header, out of view and often further buried by hiding the form input until the user clicks some icon, typically a magnifying glass. (It’s ironic we minimize the UI with a magnifying glass, isn’t it?)

The problem with burying search in a mobile context is two-fold:

  1. The feature is less apparent, and
  2. The space to enter a search query, add any filters, and display results is minimized.

That may very well be acceptable if the site has only a handful of pages to navigate. However, if the search allows a user to surface relevant content and freely move about an app, then you’re going to want to give it higher prominence.

Any service-oriented mobile app can improve user experience by providing a search box that’s immediately recognizable and with enough breathing room for tapping a virtual keyboard.

Some sites even have search forms that occupy the full screen without surrounding components, offering a “distraction-free” interface for typing queries.

No Drop-Downs, If Possible

The <select> element can negatively impact mobile UX in two glaring ways:

  1. An expanding <select> with so many options that it produces excessive scrolling.
  2. Scrolling excessively, particularly on long pages, produces an awkward situation where the page continues scrolling after already scrolling through the list of <option>s.

I’ll come across these situations, stare at my phone, and ask:

Do I really need a <select> populated with one hundred years to submit my birthdate?

Seems like an awful lot of trouble to sort through one hundred years compared to manually typing in a four-digit value myself.

A better pattern for making list selections, if absolutely needed, in a space-constrained mobile layout could be something closer to the ones used by iOS and Android devices by default. Sure, there’s scrolling involved, but within a confined space that leaves the rest of the UI alone.

A Restrained Overview

A dashboard overview in a mobile app is something that displays key data to users right off the bat, surfacing common information that the user would otherwise have to seek out. There are great use cases for dashboards, many of which you likely interact with daily, like your banking app, a project management system, or even a page showing today’s baseball scores. The WordPress dashboard is a perfect example, showing site activity, security checks, traffic, and more.

Dashboards are just fine. But the sensitive information they might contain is what worries me when I’m viewing a dashboard on a mobile device.

Let’s say I’m having dinner with friends at a restaurant. We split the check. To pay my fair share, I take out my phone and log into my banking app, and… the home screen displays my bank balance in big, bold numbers to the friends sitting right next to me, one of whom is the gossipiest of the bunch. There goes a bit of my pride.

That’s an extreme illustration because not all apps convey that level of sensitive information. But many do, and the care we put into protecting a user’s information from peeping eyeballs is only becoming more important as entire industries, like health care and education, lean more heavily into online experiences.

My advice: Hide sensitive information until prompted by the user to display it.

It’s generally a good practice to obscure sensitive information and have a liberal definition of what constitutes sensitive information.

Shortcuts Provided In The Login Flow

There’s a natural order to things, particularly when logging into a web app. We log in, see a welcome message, and are taken to a dashboard before we tap on some item that triggers some sort of action to perform. In other words, it takes a few steps and walking through a couple of doors to get to accomplish what we came to do.

What if we put actions earlier in the login flow? As in, they are displayed right along with the login form. This is what we call a shortcut.

Let’s take the same restaurant example from earlier, where I’m back at dinner and ready to pay. This time, however, I will open a different bank app. This one has shortcuts next to the login form, one of which is a “Scan to Pay” option. I tap it, log in, and am taken straight to the scanning feature that opens the camera on my device, completely bypassing any superfluous welcome messaging or dashboard. This spares the user both time and effort (and prevents sensitive information from leaking into view to boot).

Mobile operating systems also provide options for shortcuts when long-pressing an app’s icon on the home screen, which also can be used to an app’s advantage.

The Right Keyboard Configuration

All modern mobile operating systems are smart enough to tailor the virtual keyboard for specialized form inputs. A form field markup with type="email", for instance, triggers an onscreen keyboard that shows the “@" key in the primary view, preventing users from having to tap Shift to reveal it in a subsequent view. The same is true with URLs, where a “.com” key surfaces for inputs with type="url".

The right keyboard saves the effort of hunting down relevant special characters and numbers for specific fields. All we need to do is to use the right attributes and semantics for those fields, like, type=email, type=url, type=tel, and such.

<!-- Input Types for Virtual Keyboards -->
<input type="text">   <!-- default -->
<input type="tel">    <!-- numeric keyboard -->
<input type="number"> <!-- numeric keyboard -->
<input type="email">  <!-- displays @ key -->
<input type="url">    <!-- displays .com key -->
<input type="search"> <!-- displays search button -->
<input type="date">   <!-- displays date picker or wheel controls -->
Bigger Fonts With Higher Contrast

This may have been one of the first things that came to your mind when reading the article title. That’s because small text is prevalent in mobile interfaces. It’s not wrong to scale text in response to smaller screens, but where you set the lower end of the range may be too small for many users, even those with great vision.

The default size of body text is 16px on the web. That’s thanks to user agent styling that’s consistent across all browsers, including those on mobile platforms. But what exactly is the ideal size for mobile? The answer is not entirely clear. For example, Apple’s Human Interface Guidelines do not specify exact font sizes but rather focus on the use of Dynamic Text that adjusts the size of content to the user’s device-level preferences. Google’s Material Design guidelines are more concrete but are based on three scales: small, medium, and large. The following table shows the minimum font sizes for each scale based on the system’s typography tokens.

Scale Body Text (pt) Body Text (px)
Small 12pt 16px
Medium 14pt 18.66px
Large 16pt 21.33px

The real standard we ought to be looking at is the current WCAG 2.2, and here’s what it says on the topic:

“When using text without specifying the font size, the smallest font size used on major browsers for unspecified text would be a reasonable size to assume for the font.”

So, bottom line is that the bottom end of a font’s scale matches the web’s default 16px if we accept Android’s “Small” defaults. But even then, there are caveats because WCAG is more focused on contrast than size. Like, if the font in use is thin by default, WCAG suggests bumping up the font size to produce a higher contrast ratio between the text and the background it sits against.

There are many, many articles that can give you summaries of various typographical guidelines and how to adhere to them for optimal font sizing. The best advice I’ve seen, however, is Eric Bailey rallying us to “beat the “Reader Mode” button. Eric is talking more specifically about preventing clutter in an interface, but the same holds for font sizing. If the text is tiny or thin, I’m going to bash that button on your site with no hesitation.

Wrapping Up

Everything we’ve covered here in this article is personal irritations I feel when interacting with different mobile interfaces. I’m sure you have your own set of annoyances, and if you do, I’d love to read them in the comments if you’re willing to share. And someone else is likely to have even more examples.

The point is that we’re in some kind of “post-responsive” era of web design, one that looks beyond how elements stack in response to the viewport to consider user preferences, privacy, and providing optimal experiences at any breakpoint regardless of whatever device is used.

‘Prepare for the Earliest Possible AGI Deployment Scenario’

Despite the uncertain timeline for Artificial General Intelligence (AGI) becoming a reality, we need to assure responsible and ethical development today says Jen Rosiere Reynolds.

header-agi-talks-jrr.webp

As part of our new AGI Talks, experts from different backgrounds share unique insights by answering 10 questions about AI, AGI, and ASI. Kicking off the series, we are privileged to feature Jen Rosiere Reynolds, a digital communication research and Director of Strategy at a Princeton-affiliated institute dedicated to shaping policy making and accelerating research in the digital age.

About Jen Rosiere Reynolds

jrr.webp

Jen Rosiere Reynolds focuses on digital communication technology, specifically the intersection between policy and digital experiences. Currently, she is supporting the development of the Accelerator, a new research institute for evidence-based policymaking in collaboration with Princeton University. Previously, she managed research operations and helped build the Center for Social Media and Politics at NYU. Jen holds a masters degree in government from Johns Hopkins University focusing her research on domestic extremism and hate speech on social media. She has a background in national security and intelligence.

The mission of the Accelerator is to power policy-relevant research by building shared infrastructure. Through a combination of data collection, analysis, tool development, and engagement, the Accelerator aims to support the international community working to understand todays information environment i.e. the space where cognition, technology, and content converge.

AGI Talks with Jen Rosiere Reynolds

We asked Jen 10 questions about the potential risks, benefits, and future of AI:

1. What is your preferred definition of AGI?

Jen Rosiere Reynolds: AGI is a hypothetical future AI system with cognitive and emotional abilities like a human. That would include understanding context-dependent human language and understanding belief systems, succeeding at both goals and adaptability.

2. and ASI?

ASI is a speculative future AI system capable of human-outsmarting creative and complex actions. It would be able to learn any tasks that humans can, but much faster and should be able to improve its own intelligence. With our current techniques, humans would not be able to reliably evaluate or supervise ASIs.

3. In what ways do you believe AI will most significantly impact society in the next decade?

I expect to see further algorithmic development, as well as improvements in storage and computing power, which can expedite AI.

Broadly, there are so many applications of AI in various fields, like health, finance, energy, etc., and these applications are all opportunities for either justice or misuse. Lots of folks are adopting and learning how to use human-in-the-loop technologies that augment human intelligence. But right now, we still don't understand how LLMs or other AI are influencing the information environment at a system level, and that's really concerning to me. It's not just about what happens when you input something into a generative AI system and whether it produces something egregious. It's also about what impact the use of AI may have on our society and world.

I've heard 2024 referred to as the year of elections. We see that in the United States as well as in so many global elections that have already taken place this year and will continue this summer and fall. We need to be really thoughtful about what effect influence operations have on elections and national security. It's challenging right now to understand the impact of deep fakes or the manipulation or creation of documents and images have to influence or affect people's decision-making. We saw CIA, FBI, and NSA confirm Russian interference in the 2016 US Presidential election and there was a US information operation on Facebook and Twitter that got taken down back in 2022, but what's the impact? The US-led online effort got thousands of followers, but that doesn't mean that thousands of people saw the information, that their minds or actions changed. I hope very soon we can understand how people typically understand and interact with the information environment, so we can talk about measurements and impact more precisely. In the next decade I expect we can much more specifically understand how AI and the use of AI affects our world.

4. What do you think is the biggest benefit associated with AI?

Right now, I think that the biggest benefit associated with AI lies in its potential to minimize harm in various scenarios. AI could assist in identifying and prosecuting child sexual exploitation without exposing investigators to the imagery and analyze the data much more efficiently, resulting in faster, more accurate, and less harmful analysis. AI could help with early diagnosis and support the development of new life-saving medicines. AI could also help reduce decision-making bias in criminal justice sentencing and job recruitment. All of these can happen, but there are also decisions to be made, and that's where education and open discussion is important, so that we can prioritize values over harm.

5. and the biggest risk of AI?

Right now, I see two significant risks associated with the development of AI that are the most urgent and impactful. The first is the need to ensure that AI development is responsible and ethical. AI has the potential to be used for harmful purposes, perpetuating hatred, prejudice, and authoritarianism. The second risk is that policymakers struggle to keep up with the rapid pace of AI development. Any regulation could quickly become outdated and ineffective, potentially hindering innovation while also failing to protect individuals and society at large.

6. In your opinion, will AI have a net positive impact on society?

I think that AI has great potential to make a positive impact on society. I see AI as a tool that people develop and use. My concern lies not with the tool itself, but with people how we, as humans, choose to develop and use the tools. There is long ongoing debate in the national security space about what should be developed, because of the potential for harmful use and misuse; these discussions should absolutely inform conversations about the development of AI. I am encouraged by the general attention that AI and its potential uses are currently receiving and do believe that broad and inclusive open debate will lead to positive outcomes.

7. Where are the limits of human control over AI systems?

Focus on the limits of human control over AI systems may be a bit premature and potentially move focus away from more immediate issues. We don't fully understand the impact of AI that is currently deployed, and it's difficult to estimate the limits of human control over what might be developed in the future.

8. Do you think AI can ever truly understand human values or possess consciousness?

I can imagine AI being able to intellectually understand the outward manifestation of values (i.e., how does a person act when they are being patient). When raising the issue of whether technology can truly feel or possess consciousness, we get into debates that are reflected across society and the world that raises questions like, what is consciousness and when does personhood begin? We can see these debates around end-of-life care, for example. While I personally don't believe that AI could truly manifest the essence of a human, I know that others would disagree based on their understanding and beliefs of consciousness and personhood.

9. Do you think your job as a researcher will ever be replaced by AI?

Maybe. I think that lots of jobs could potentially be replaced, or at least parts of jobs could potentially be replaced. I think we see that right now, with the human-in-the-loop tools, a part of someone's job may be much more efficient or quick. This can be very threatening to people. I think everyone should have the dignity of work and the opportunity to make a living. If there are cases where technology results in job displacement, society should take responsibility say that yes, we allowed this to happen and support those affected people.

10. We will reach AGI by the year?

OpenAI announced that they expect the development of AGI within the next decade, though I haven't come across any other researchers who share such an aggressive timeline. I'd recommend to prepare as best as possible for the earliest possible AGI deployment scenario as there are several unknown elements in the equation right now future advancement of algorithms and future improvements in storage and compute power.

APIs and SDKs in a PHP project

I want to understand how I can add an SDK to my PHP projects to make APIs calls. I noticed that every software company have an SDK. I also noticed that most SDKs use Composer. I don't know what composer is and do I need to have it for every SDK?

I am also using PHP procedural programming and I noticed that these SDKs use OOP.

Can someone help me make my first API call using an SDK?

6 Important WordPress Server Requirements You Should Know

Recently, one of our users asked what the recommended server requirements are for running a WordPress website.

The best thing about WordPress is that it will work in almost any kind of environment. However, when you’re picking a hosting solution for your site, it’s important to check whether it meets the basic prerequisites or not.

In this article, we will share important WordPress server requirements you should know.

Important WordPress server requirements

Why is it Important to Check Server Requirements?

All WordPress websites on the internet need a server to function. They are used to store and use website files, databases, media files, content, and other important data.

When it comes to running WordPress smoothly, there are some server requirements you should look into. Technically, WordPress will work in minimalist conditions, like on outdated versions of PHP or basic hardware, but it’s not ideal.

WordPress server plays a big role in your site’s performance. Limited server specifications can slow down your site, which can have a negative impact on user experience and keyword rankings.

It will also make it difficult to handle large spikes in traffic. If you run multiple WordPress plugins and third-party tools, then meeting server requirements is critical. Otherwise, you’ll risk breaking your site or experiencing sluggish performance.

That said, let’s look at the server requirements for WordPress. You can click the links below to jump ahead to any section:

Important WordPress Server Requirements

To run WordPress, you will need to check some prerequisites. These include the PHP version, MySQL or MariaDB version, HTTPS support, web server type, storage space, and other hardware specifications.

Let’s take a closer look at each of these requirements.

WordPress currently requires PHP version 7.4 or higher to work smoothly. PHP is a programming language for creating dynamic interactive websites. It is open source and WordPress is written using PHP.

Just like any other programming language, there are many versions of PHP you can use. Each version receives updates and fixes for up to 2 years. While WordPress officially recommends PHP version 7.4, it no longer gets any security updates.

That’s why we would suggest using the latest version. If you already have a WordPress site, then it’s better to update the PHP version at the earliest.

This will protect your site from security vulnerabilities, bugs, malware, and hackers. Plus, it will improve performance by running processes much faster and reducing memory usage.

You can also check the PHP version of your server by going to Tools » Site Health from the WordPress dashboard. From here, switch to the ‘Info’ tab.

Opening the Info tab inside the Site Health menu in the WordPress admin area

Next, you can scroll down to the ‘Server’ tab.

Go ahead and click the tab to expand the Server section and view the server’s system information along with the PHP version.

Checking your server's PHP version in the WordPress Site Health page

Besides that, you should also check the PHP memory allocated by the WordPress server. PHP memory is the amount of memory reserved for running PHP-based processes.

The standard PHP memory used by WordPress is 64MB, but this is often not high enough. If a task or process requires more memory to work, then it could lead to the WordPress memory exhausted error.

A simple fix is to increase the PHP memory by manually editing the wp-config.php file or .htaccess file. Or you can reach out to your web hosting provider and increase the limit.

2. Check for Suggested MySQL or MariaDB Versions

WordPress recommends MySQL version 5.7 or greater and MariaDB version 10.4 or higher to function.

MySQL and MariaDB are database management systems used by WordPress to store and retrieve blog information. You only need any one of the systems to install and use WordPress on a server.

You can easily access the databases from your hosting provider’s cPanel. For instance, simply use phpMyAdmin to access the MySQL database in your web browser.

phpMyAdmin

However, when checking the WordPress server requirements, make sure that the database is stored on a solid-state drive (SSD). It is the fastest storage technology currently available and offers quick performance.

You should also see if the server offers automated database optimization and if there is an option for automated database backups.

3. Look for NGINX or Apache Web Server Software

The optimal web server software recommended by WordPress is NGINX or Apache. While it is not mandatory to run WordPress, using either software has certain advantages.

For instance, Apache is an open-source server software that is fast, reliable, and secure. It powers almost 31% of web servers and is highly customizable. You can use different extensions and modules to meet the needs of any environment.

On the other hand, NGINX is newer and faster and requires fewer resources to run than Apache. It runs more than 34% of web servers and is developed to address performance issues. However, it doesn’t offer the flexibility that you’d get with Apache.

When looking for a web server for your WordPress site, either Apache or NGINX is a great choice.

PRO TIP: Many users have had great success with Litespeed server software as well. If you’re interested in checking it out, we recommend using Hostinger because they have optimized Litespeed hosting for as low as $2.99 per month.

4. Support for HTTPS by WordPress Server

HTTPS, or hypertext transfer protocol secure, is an encryption method that secures the connection between your server and your user’s browser. It is an extension of HTTP, and all web addresses begin with HTTPS.

The HTTPS protocol in WPBeginner's domain

HTTPS makes it harder for hackers to eavesdrop on your connection, and it helps make your site more secure. Plus, it also sends a positive signal to search engines like Google and helps improve your WordPress SEO.

That’s why it’s important to check if your WordPress server supports HTTPS and offers SSL certificates.

For more details, you can see our guide on how to get a free SSL certificate for your WordPress website.

5. WordPress Server Hardware Requirements

When choosing a WordPress server, you should also look into some basic hardware specifications.

That’s because a web server is actually a physical server that stores and shares websites with people on the internet. If the hardware requirements are limited, then you could run into storage issues, poor performance, and other WordPress errors.

Some important hardware requirements include checking the disk space available for storage, RAM (random access memory), and CPU (central processing unit).

  • Storage (Disk Space) – The minimum disk space requirement for WordPress is 1 GB. However, we suggest looking for servers that offer at least 10 GB or more storage. WordPress will use disk space to store website files, images, videos, plugins, themes, and other data. So, as your site grows, it is better to have enough space to keep your website running smoothly. Plus, look for SSD drives as they are faster than the standard HDD (hard disk drives).
  • Memory (RAM) – It acts as a link between your server’s hard disk and processor. RAM speeds up server processes by temporarily storing data required by the CPU from the hard disk. WordPress itself only requires at least 512 MB of RAM, but look for a web server that has an option for expansion. As your site grows, you’ll need more RAM to improve performance.
  • Processing Power (CPU) – The processor or CPU is the brain of your web server, and it controls how many processes can happen at a given time. Its performance is usually measured in gigahertz (GHz) or the number of cores available. WordPress requires only a 1.0 GHz CPU to work normally. However, more powerful processors will have multiple cores and deliver faster performance.

To learn more, please see our guide on how to determine the ideal size of a web server for your website.

6. Check Your WordPress Server Location and CDN Option

The physical distance between your site’s server location and the user’s location can affect the loading speed of your website. If a user is located near your server, then your site will load faster compared to someone living further away.

To speed up your WordPress site, many web servers offer a content delivery network (CDN).

It is a network of servers spread across the globe, and they store static versions of your site. When a user wants to view your content, the closest server in the CDN will instantly load the website.

Content Delivery Network (CDN)

Even though it’s not a technical server requirement, when you’re looking at hosting companies for your site’s needs and requirements, there is an added advantage if the one you choose offers a CDN.

You may want to see our list of the best WordPress CDN services.

Bonus: Pick the Best WordPress Servers

Now that you know some important WordPress server specifications, the next step is to pick a hosting solution that meets these requirements.

In our 16+ years of experience, we’ve tested multiple website hosts. And to help you out, here are some of the best hosting providers you can choose from.

1. Bluehost

bluehost website

Bluehost is the oldest web host in the market, and they’re an official WordPress-recommended hosting provider.

It offers a free domain for 1 year, a free SSL certificate, and a 1-click WordPress installation with every plan. Plus, you get SSD web storage space starting from 10 GB and going all the way up to 100 GB.

Besides that, it offers free CDN with every pricing plan. If you opt for dedicated hosting, then you get a minimum of 4 CPU cores (2.3 GHz) and 1TB HDD storage.

2. SiteGround

SiteGround web hosting

SiteGround is one of the most popular and highest-rated hosting providers. They provide a unique in-house speed and security solution for WordPress.

With SiteGround, you get free WordPress installation, 10 GB of web storage space that goes up to 40 GB, a free SSL certificate for HTTPS support, free CDN, and more.

It easily meets the minimum WordPress server requirements and offers advanced solutions. For instance, it automatically updates the PHP version once it is stable, and lets you create unlimited MySQL databases, offers SSD storage, and more.

3. Hostinger

Hostinger website

Hostinger is one of the fastest WordPress hosting services in the industry. It offers automatic 1-click WordPress install, free CDN, free domain name, and 24/7 customer support.

The best part about Hostinger is that the minimum storage space it offers is 100 GB, which goes up to 200 GB. Plus, it offers the fastest SSD technology currently available.

Besides that, you get free SSL, unlimited bandwidth, regular backups, unlimited databases, and multiple PHP version support. Their shared plans also run on Litespeed web server software, a popular alternative to Apache and NGINX.

If you want more options for picking a website server, then please see our guide on how to choose the best WordPress hosting.

We hope this article helped you learn about important WordPress server requirements you should know about. You may also want to see our guide on the difference between a domain name and web hosting and how to move WordPress from HTTP to HTTPS.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post 6 Important WordPress Server Requirements You Should Know first appeared on WPBeginner.

How to Optimize RecyclerView performance by implementing the ViewHolder

When working with RecyclerView, always utilize the ViewHolder pattern to improve performance by minimizing the number of findViewById() calls.

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView;

        public ViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.textView);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.textView.setText("Item " + position);
    }

    @Override
    public int getItemCount() {
        return 100; // Example size, use your actual data size here
    }
}

By caching references to views in the ViewHolder, you avoid repeatedly calling findViewById() in onBindViewHolder(), resulting in smoother scrolling and improved efficiency.

Context: The ViewHolder pattern is crucial in Android development, especially when dealing with RecyclerViews. It's included here because optimizing RecyclerView performance is a common concern for Android developers. Without ViewHolder, each call to findViewById() in onBindViewHolder() can lead to performance issues, especially with large datasets. Implementing this pattern significantly enhances app responsiveness and user experience.

Bouncing Balls: Creating a new ball when two balls collide

Hello,
I have a program which creates multiple balls and bounces them off when they collide. This works fine.

import java.awt.Rectangle;
public class Ball{
    private int x = 0;        
    private int y = 0;        
    private int radius;
    private int panelwidth = 500;
    private int panelheight = 500;
    private int xDx = 1;        
    private int yDy = 1;        
    private boolean xUp, yUp;
    public Ball(int x, int y, int radius){
        this.x = x;
        this.y = y;
        this.radius = radius;
        this.xUp = false;
        this.yUp = false;
        this.xDx = 1;
        this.yDy = 1;
    }

    public void move(){
        if ( y <= 0 ) {
            yUp = true;
            yDy = ( int ) ( Math.random() * 5 + 2 );
        }
        else if ( y >= this.panelheight - 2* this.radius ) {
            yDy = ( int ) ( Math.random() * 5 + 2 );
            yUp = false;
        }
        if ( x <= 0 ) {
            xUp = true;
            xDx = ( int ) ( Math.random() * 5 + 2 );
        }
        else if ( x >= this.panelwidth - 2 * this.radius ) {
            xUp = false;
            xDx = ( int ) ( Math.random() * 5 + 2 );
        }
        if (xUp)
            x += xDx;
        else
            x -= xDx;
        if ( yUp )
            y += yDy;
        else
            y -= yDy;
    }

    public int getX(){
        return this.x;
    }

    public int getY(){
        return this.y;
    }

    public void changeDirection(Ball b){
        if (this.x <= b.x && this.y <= b.y){
            this.xUp = false;
            this.yUp = false;
            b.xUp = true;
            b.yUp = true;
        }
        else if (this.x <= b.x && this.y >= b.y){
            this.xUp = false;
            this.yUp = true;
            b.xUp = true;
            b.yUp = false;
        }
    }

    public void setY(int y ){
        this.y = y;
    }

    public int getRadius(){
        return this.radius;
    }

    public Rectangle getBounds(){
        return new Rectangle(this.x, this.y, this.radius, this.radius);
    }

    public boolean collides(Ball b){
        return this.getBounds().intersects(b.getBounds());
    }

}



import javax.swing.JFrame;

public class Frame{
    public static void main( String args[] ) {
        JFrame frame = new JFrame( "Bouncing Balls" );
        Ball b[] = new Ball[6];
        b[0] = new Ball (10, 10,40);
        b[1] = new Ball (100, 100, 40);
        b[2] = new Ball (20, 188,40);
        b[3] = new Ball (144, 100,40);
        b[4] = new Ball (220, 138,40);
        b[5] = new Ball (14, 10,40);

        BallPanel bp = new BallPanel(b); 
        frame.add( bp );
        frame.setSize( 500, 500 ); 
        frame.setVisible( true ); 
    }
}





import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.Graphics;
import java.awt.Color;
public class BallPanel extends JPanel implements ActionListener {
    private int delay = 10;
    protected Timer timer;
    Ball b[];
    public BallPanel(Ball b[]) {
        this.b= new Ball[b.length];
        for (int i = 0; i <b.length; i++){
            this.b[i] = b[i];
        }
        timer = new Timer(delay, this);
        timer.start();        
    }

    public void actionPerformed(ActionEvent e) {
        repaint();
    }

    public void paintComponent( Graphics g )  {
        super.paintComponent( g ); 
        g.setColor(Color.red);
        // move the balls
        for (int i = 0; i <b.length; i++){
            this.b[i].move();
        }
        // check for collision and change direction if balls collide
         for (int i = 0; i <b.length; i++){
              for (int j = 0; j <b.length; j++){
                  if (i!= j && b[i].collides(b[j])){
                      b[i].changeDirection(b[j]);
                  }
              }

        }
        // draw the balls
        for (int i = 0; i <b.length; i++){
            g.fillOval(this.b[i].getX(),  this.b[i].getY() , this.b[i].getRadius(), this.b[i].getRadius());
        }
    }
}

I would like to add a new ball when two balls collide in the Ball Panel class. When I tried creating a new ball in the nested loop that checks for collision (used an array list), and then called the move and the fill oval methods, the program froze. Can you tell me why? What is the proper way to handle creating a new ball upon collision and make it move etc.?

Thank you